Class FixedWidthWriterSettings
java.lang.Object
com.univocity.parsers.common.CommonSettings<FixedWidthFormat>
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.
- Author:
- Univocity Software Pty Ltd - parsers@univocity.com
- See Also:
-
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 voidaddConfiguration(Map<String, Object> out) voidaddFormatForLookahead(String lookahead, FixedWidthFields lengths) Defines the format of records identified by a lookahead symbol.voidaddFormatForLookbehind(String lookbehind, FixedWidthFields lengths) Defines the format of records identified by a lookbehind symbol.final FixedWidthWriterSettingsclone()Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.protected final FixedWidthWriterSettingsclone(boolean clearInputSpecificSettings) Deprecated.doesn't really make sense for fixed-width.final FixedWidthWriterSettingsclone(FixedWidthFields fields) Clones this configuration object to reuse most user-provided settings.protected voidconfigureFromAnnotations(Class<?> beanClass) Configures the writer based on the annotations provided in a given classprotected FixedWidthFormatReturns the default FixedWidthFormat configured to handle Fixed-Width outputsReturns the default alignment to use when writing headers.intReturns the hard limit of how many columns a record can have (defaults to 512).booleanIndicates 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 totruebooleanReturns a flag indicating whether each record, when written, should be followed by a line separator (as specified inFormat.getLineSeparator().voidsetDefaultAlignmentForHeaders(FieldAlignment defaultAlignmentForHeaders) Defines the default alignment to use when writing headers.voidsetUseDefaultPaddingForHeaders(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...))voidsetWriteLineSeparatorAfterRecord(boolean writeLineSeparatorAfterRecord) Defines whether each record, when written, should be followed by a line separator (as specified inFormat.getLineSeparator().Methods inherited from class CommonWriterSettings
clearInputSpecificSettings, getEmptyValue, getExpandIncompleteRows, getRowWriterProcessor, isColumnReorderingEnabled, isHeaderWritingEnabled, setColumnReorderingEnabled, setEmptyValue, setExpandIncompleteRows, setHeaderWritingEnabled, setRowWriterProcessorMethods inherited from class 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
-
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 ofFixedWidthFieldswhich 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
-
createDefaultFormat
Returns the default FixedWidthFormat configured to handle Fixed-Width outputs- Specified by:
createDefaultFormatin classCommonSettings<FixedWidthFormat>- Returns:
- and instance of FixedWidthFormat configured to handle Fixed-Width outputs
-
getMaxColumns
public int getMaxColumns()Description copied from class:CommonSettingsReturns 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:
getMaxColumnsin 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.
-
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:
trueif 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
nullif 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.nullindicates 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:CommonWriterSettingsConfigures the writer based on the annotations provided in a given class- Overrides:
configureFromAnnotationsin classCommonWriterSettings<FixedWidthFormat>- Parameters:
beanClass- the classes whose annotations will be processed to derive configurations for writing.
-
addConfiguration
- Overrides:
addConfigurationin classCommonWriterSettings<FixedWidthFormat>
-
clone
Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.- Overrides:
clonein 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:
clonein 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.
-