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:
Cloneable
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
FieldsModifier and TypeFieldDescriptionprivate FieldAlignment
private FixedWidthFields
private Map<String,
FixedWidthFields> private Map<String,
FixedWidthFields> private boolean
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionprotected void
addConfiguration
(Map<String, Object> out) void
addFormatForLookahead
(String lookahead, FixedWidthFields lengths) Defines the format of records identified by a lookahead symbol.void
addFormatForLookbehind
(String lookbehind, FixedWidthFields lengths) Defines the format of records identified by a lookbehind symbol.final FixedWidthWriterSettings
clone()
Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.protected final FixedWidthWriterSettings
clone
(boolean clearInputSpecificSettings) Deprecated.doesn't really make sense for fixed-width.private FixedWidthWriterSettings
clone
(boolean clearInputSpecificSettings, FixedWidthFields fields) final FixedWidthWriterSettings
clone
(FixedWidthFields fields) Clones this configuration object to reuse most user-provided settings.protected void
configureFromAnnotations
(Class<?> beanClass) Configures the writer based on the annotations provided in a given classprotected FixedWidthFormat
Returns the default FixedWidthFormat configured to handle Fixed-Width outputs(package private) int[]
Returns the sequence of field lengths to be written to form a record.Returns the default alignment to use when writing headers.(package private) FieldAlignment[]
Returns the sequence of field alignments to apply to each field in the record.(package private) int[]
Returns the sequence of field lengths to be written to form a record.(package private) char[]
Returns the sequence of paddings used by each field of each record.(package private) boolean[]
Returns the sequence of fields to ignore.(package private) Lookup[]
(package private) Lookup[]
int
Returns the hard limit of how many columns a record can have (defaults to 512).boolean
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
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) final 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 Details
-
fieldLengths
-
lookaheadFormats
-
lookbehindFormats
-
useDefaultPaddingForHeaders
private boolean useDefaultPaddingForHeaders -
defaultAlignmentForHeaders
-
writeLineSeparatorAfterRecord
private boolean writeLineSeparatorAfterRecord
-
-
Constructor Details
-
FixedWidthWriterSettings
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:
-
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 Details
-
setFieldLengths
-
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
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
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
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
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
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
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
- Overrides:
addConfiguration
in classCommonWriterSettings<FixedWidthFormat>
-
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.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
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
-