Package com.univocity.parsers.fixed
Class FixedWidthWriterSettings
- java.lang.Object
-
- com.univocity.parsers.common.CommonSettings<F>
-
- com.univocity.parsers.common.CommonWriterSettings<FixedWidthFormat>
-
- com.univocity.parsers.fixed.FixedWidthWriterSettings
-
- All Implemented Interfaces:
java.lang.Cloneable
public class FixedWidthWriterSettings extends CommonWriterSettings<FixedWidthFormat>
This is the configuration class used by the Fixed-Width writer (FixedWidthWriter
)The FixedWidthWriterSettings provides all configuration options in
CommonWriterSettings
and currently does not require any additional setting.The FixedWidthParserSettings requires a definition of the field lengths of each record in the input. This must provided using an instance of
FixedWidthFields
.
-
-
Field Summary
Fields Modifier and Type Field Description private FieldAlignment
defaultAlignmentForHeaders
private FixedWidthFields
fieldLengths
private java.util.Map<java.lang.String,FixedWidthFields>
lookaheadFormats
private java.util.Map<java.lang.String,FixedWidthFields>
lookbehindFormats
private boolean
useDefaultPaddingForHeaders
private boolean
writeLineSeparatorAfterRecord
-
Constructor Summary
Constructors Constructor Description FixedWidthWriterSettings()
Creates a basic configuration object for the Fixed-Width writer with no field length configuration.FixedWidthWriterSettings(FixedWidthFields fieldLengths)
You can only create an instance of this class by providing a definition of the field lengths of each record in the input.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
addConfiguration(java.util.Map<java.lang.String,java.lang.Object> out)
void
addFormatForLookahead(java.lang.String lookahead, FixedWidthFields lengths)
Defines the format of records identified by a lookahead symbol.void
addFormatForLookbehind(java.lang.String lookbehind, FixedWidthFields lengths)
Defines the format of records identified by a lookbehind symbol.FixedWidthWriterSettings
clone()
Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.protected FixedWidthWriterSettings
clone(boolean clearInputSpecificSettings)
Deprecated.doesn't really make sense for fixed-width.private FixedWidthWriterSettings
clone(boolean clearInputSpecificSettings, FixedWidthFields fields)
FixedWidthWriterSettings
clone(FixedWidthFields fields)
Clones this configuration object to reuse most user-provided settings.protected void
configureFromAnnotations(java.lang.Class<?> beanClass)
Configures the writer based on the annotations provided in a given classprotected FixedWidthFormat
createDefaultFormat()
Returns the default FixedWidthFormat configured to handle Fixed-Width outputs(package private) int[]
getAllLengths()
Returns the sequence of field lengths to be written to form a record.FieldAlignment
getDefaultAlignmentForHeaders()
Returns the default alignment to use when writing headers.(package private) FieldAlignment[]
getFieldAlignments()
Returns the sequence of field alignments to apply to each field in the record.(package private) int[]
getFieldLengths()
Returns the sequence of field lengths to be written to form a record.(package private) char[]
getFieldPaddings()
Returns the sequence of paddings used by each field of each record.(package private) boolean[]
getFieldsToIgnore()
Returns the sequence of fields to ignore.(package private) Lookup[]
getLookaheadFormats()
(package private) Lookup[]
getLookbehindFormats()
int
getMaxColumns()
Returns the hard limit of how many columns a record can have (defaults to 512).boolean
getUseDefaultPaddingForHeaders()
Indicates whether headers should be written using the default padding specified inFixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (inFixedWidthFields.setPadding(char, int...)
) Defaults totrue
boolean
getWriteLineSeparatorAfterRecord()
Returns a flag indicating whether each record, when written, should be followed by a line separator (as specified inFormat.getLineSeparator()
.void
setDefaultAlignmentForHeaders(FieldAlignment defaultAlignmentForHeaders)
Defines the default alignment to use when writing headers.(package private) void
setFieldLengths(FixedWidthFields fieldLengths)
void
setUseDefaultPaddingForHeaders(boolean useDefaultPaddingForHeaders)
Defines whether headers should be written using the default padding specified inFixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (inFixedWidthFields.setPadding(char, int...)
)void
setWriteLineSeparatorAfterRecord(boolean writeLineSeparatorAfterRecord)
Defines whether each record, when written, should be followed by a line separator (as specified inFormat.getLineSeparator()
.-
Methods inherited from class com.univocity.parsers.common.CommonWriterSettings
clearInputSpecificSettings, getEmptyValue, getExpandIncompleteRows, getRowWriterProcessor, isColumnReorderingEnabled, isHeaderWritingEnabled, setColumnReorderingEnabled, setEmptyValue, setExpandIncompleteRows, setHeaderWritingEnabled, setRowWriterProcessor
-
Methods inherited from class com.univocity.parsers.common.CommonSettings
excludeFields, excludeFields, excludeIndexes, getErrorContentLength, getFormat, getHeaders, getIgnoreLeadingWhitespaces, getIgnoreTrailingWhitespaces, getMaxCharsPerColumn, getNullValue, getProcessorErrorHandler, getRowProcessorErrorHandler, getSkipBitsAsWhitespace, getSkipEmptyLines, getWhitespaceRangeStart, isAutoConfigurationEnabled, isProcessorErrorHandlerDefined, selectFields, selectFields, selectIndexes, setAutoConfigurationEnabled, setErrorContentLength, setFormat, setHeaders, setIgnoreLeadingWhitespaces, setIgnoreTrailingWhitespaces, setMaxCharsPerColumn, setMaxColumns, setNullValue, setProcessorErrorHandler, setRowProcessorErrorHandler, setSkipBitsAsWhitespace, setSkipEmptyLines, toString, trimValues
-
-
-
-
Field Detail
-
fieldLengths
private FixedWidthFields fieldLengths
-
lookaheadFormats
private java.util.Map<java.lang.String,FixedWidthFields> lookaheadFormats
-
lookbehindFormats
private java.util.Map<java.lang.String,FixedWidthFields> lookbehindFormats
-
useDefaultPaddingForHeaders
private boolean useDefaultPaddingForHeaders
-
defaultAlignmentForHeaders
private FieldAlignment defaultAlignmentForHeaders
-
writeLineSeparatorAfterRecord
private boolean writeLineSeparatorAfterRecord
-
-
Constructor Detail
-
FixedWidthWriterSettings
public FixedWidthWriterSettings(FixedWidthFields fieldLengths)
You can only create an instance of this class by providing a definition of the field lengths of each record in the input.This must provided using an instance of
FixedWidthFields
.- Parameters:
fieldLengths
- the instance ofFixedWidthFields
which provides the lengths of each field in the fixed-width records to be parsed- See Also:
FixedWidthFields
-
FixedWidthWriterSettings
public FixedWidthWriterSettings()
Creates a basic configuration object for the Fixed-Width writer with no field length configuration. This constructor is intended to be used when the record length varies depending of the input row. Refer toaddFormatForLookahead(String, FixedWidthFields)
,addFormatForLookbehind(String, FixedWidthFields)
-
-
Method Detail
-
setFieldLengths
final void setFieldLengths(FixedWidthFields fieldLengths)
-
getFieldLengths
int[] getFieldLengths()
Returns the sequence of field lengths to be written to form a record.- Returns:
- the sequence of field lengths to be written to form a record.
-
getAllLengths
int[] getAllLengths()
Returns the sequence of field lengths to be written to form a record.- Returns:
- the sequence of field lengths to be written to form a record.
-
getFieldAlignments
FieldAlignment[] getFieldAlignments()
Returns the sequence of field alignments to apply to each field in the record.- Returns:
- the sequence of field alignments to apply to each field in the record.
-
getFieldPaddings
char[] getFieldPaddings()
Returns the sequence of paddings used by each field of each record.- Returns:
- the sequence of paddings used by each field of each record.
-
getFieldsToIgnore
boolean[] getFieldsToIgnore()
Returns the sequence of fields to ignore.- Returns:
- the sequence of fields to ignore.
-
createDefaultFormat
protected FixedWidthFormat createDefaultFormat()
Returns the default FixedWidthFormat configured to handle Fixed-Width outputs- Specified by:
createDefaultFormat
in classCommonSettings<FixedWidthFormat>
- Returns:
- and instance of FixedWidthFormat configured to handle Fixed-Width outputs
-
getMaxColumns
public int getMaxColumns()
Description copied from class:CommonSettings
Returns the hard limit of how many columns a record can have (defaults to 512). You need this to avoid OutOfMemory errors in case of inputs that might be inconsistent with the format you are dealing with .- Overrides:
getMaxColumns
in classCommonSettings<FixedWidthFormat>
- Returns:
- The maximum number of columns a record can have.
-
addFormatForLookahead
public void addFormatForLookahead(java.lang.String lookahead, FixedWidthFields lengths)
Defines the format of records identified by a lookahead symbol.- Parameters:
lookahead
- the lookahead value that when found in the output row, will notify the writer to switch to a new record format, with different field lengthslengths
- the field lengths of the record format identified by the given lookahead symbol.
-
addFormatForLookbehind
public void addFormatForLookbehind(java.lang.String lookbehind, FixedWidthFields lengths)
Defines the format of records identified by a lookbehind symbol.- Parameters:
lookbehind
- the lookbehind value that when present in the previous output row, will notify the writer to switch to a new record format, with different field lengthslengths
- the field lengths of the record format identified by the given lookbehind symbol.
-
getLookaheadFormats
Lookup[] getLookaheadFormats()
-
getLookbehindFormats
Lookup[] getLookbehindFormats()
-
getUseDefaultPaddingForHeaders
public boolean getUseDefaultPaddingForHeaders()
Indicates whether headers should be written using the default padding specified inFixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (inFixedWidthFields.setPadding(char, int...)
) Defaults totrue
- Returns:
true
if the default padding is to be used when writing headers, otherwisefalse
-
setUseDefaultPaddingForHeaders
public void setUseDefaultPaddingForHeaders(boolean useDefaultPaddingForHeaders)
Defines whether headers should be written using the default padding specified inFixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (inFixedWidthFields.setPadding(char, int...)
)- Parameters:
useDefaultPaddingForHeaders
- flag indicating whether the default padding is to be used when writing headers
-
getDefaultAlignmentForHeaders
public FieldAlignment getDefaultAlignmentForHeaders()
Returns the default alignment to use when writing headers. If none is specified (i.e.null
), the headers will be aligned according to the corresponding field alignment inFixedWidthFields.getAlignment(String)
. Defaults tonull
.- Returns:
- the default alignment for headers, or
null
if the headers should be aligned according to the column alignment.
-
setDefaultAlignmentForHeaders
public void setDefaultAlignmentForHeaders(FieldAlignment defaultAlignmentForHeaders)
Defines the default alignment to use when writing headers. If none is specified (i.e.null
), the headers will be aligned according to the corresponding field alignment inFixedWidthFields.getAlignment(String)
. Defaults tonull
.- Parameters:
defaultAlignmentForHeaders
- the alignment to use when writing headers.null
indicates that headers should be aligned according to the column alignment.
-
getWriteLineSeparatorAfterRecord
public boolean getWriteLineSeparatorAfterRecord()
Returns a flag indicating whether each record, when written, should be followed by a line separator (as specified inFormat.getLineSeparator()
. Consider the records[a,b]
and[c,d]
, with field lengths[2, 2]
, and line separator =\n
:- When
getWriteLineSeparatorAfterRecord()
is enabled, the output will be written as:a b \nc d \n
- When
getWriteLineSeparatorAfterRecord()
is disabled, the output will be written as:a b c d
true
.- Returns:
- whether the writer should add a line separator after a record is written to the output.
- When
-
setWriteLineSeparatorAfterRecord
public void setWriteLineSeparatorAfterRecord(boolean writeLineSeparatorAfterRecord)
Defines whether each record, when written, should be followed by a line separator (as specified inFormat.getLineSeparator()
. Consider the records[a,b]
and[c,d]
, with field lengths[2, 2]
, and line separator =\n
:- When
getWriteLineSeparatorAfterRecord()
is enabled, the output will be written as:a b \nc d \n
- When
getWriteLineSeparatorAfterRecord()
is disabled, the output will be written as:a b c d
true
.- Parameters:
writeLineSeparatorAfterRecord
- flag indicating whether the writer should add a line separator after a record is written to the output.
- When
-
configureFromAnnotations
protected void configureFromAnnotations(java.lang.Class<?> beanClass)
Description copied from class:CommonWriterSettings
Configures the writer based on the annotations provided in a given class- Overrides:
configureFromAnnotations
in classCommonWriterSettings<FixedWidthFormat>
- Parameters:
beanClass
- the classes whose annotations will be processed to derive configurations for writing.
-
addConfiguration
protected void addConfiguration(java.util.Map<java.lang.String,java.lang.Object> out)
- Overrides:
addConfiguration
in classCommonWriterSettings<FixedWidthFormat>
-
clone
public final FixedWidthWriterSettings clone()
Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.- Overrides:
clone
in classCommonWriterSettings<FixedWidthFormat>
- Returns:
- a copy of all configurations applied to the current instance.
-
clone
@Deprecated protected final FixedWidthWriterSettings clone(boolean clearInputSpecificSettings)
Deprecated.doesn't really make sense for fixed-width. . Use alternative methodclone(FixedWidthFields)
.Clones this configuration object to reuse most user-provided settings. This includes the fixed-width field configuration, but doesn't include other input-specific settings. This method is meant to be used internally only.- Overrides:
clone
in classCommonWriterSettings<FixedWidthFormat>
- Parameters:
clearInputSpecificSettings
- flag indicating whether to clear settings that are likely to be associated with a given input.- Returns:
- a copy of all configurations applied to the current instance.
-
clone
public final FixedWidthWriterSettings clone(FixedWidthFields fields)
Clones this configuration object to reuse most user-provided settings. Properties that are specific to a given input (such as header names and selection of fields) will be reset to their defaults. To obtain a full copy, useclone()
.- Parameters:
fields
- the fixed-width field configuration to be used by the cloned settings object.- Returns:
- a copy of the general configurations applied to the current instance.
-
clone
private FixedWidthWriterSettings clone(boolean clearInputSpecificSettings, FixedWidthFields fields)
-
-