public class FixedWidthParserSettings extends CommonParserSettings<FixedWidthFormat>
FixedWidthParser
)
In addition to the configuration options provided by CommonParserSettings
, the FixedWidthParserSettings include:
For example, if the record length is 5, but the row contains "12345678\n", then portion containing "678" will be discarded and not considered part of the next record
For example, if recordEndsOnNewline is set to true, then given a record of length 4, and the input "12\n3456", the parser will identify [12] and [3456]
If recordEndsOnNewline is set to false, then given a record of length 4, and the input "12\n3456", the parser will identify a multi-line record [12\n3] and [456 ]
The FixedWidthParserSettings need a definition of the field lengths of each record in the input. This must provided using an instance of FixedWidthFields
.
FixedWidthParser
,
FixedWidthFormat
,
FixedWidthFields
,
CommonParserSettings
Modifier and Type | Field and Description |
---|---|
protected boolean |
recordEndsOnNewline |
protected boolean |
skipTrailingCharsUntilNewline |
headerExtractionEnabled
Constructor and Description |
---|
FixedWidthParserSettings()
Creates a basic configuration object for the Fixed-Width parser with no field length configuration.
|
FixedWidthParserSettings(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.
|
Modifier and Type | Method and Description |
---|---|
protected 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.
|
FixedWidthParserSettings |
clone()
Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.
|
protected FixedWidthParserSettings |
clone(boolean clearInputSpecificSettings)
Deprecated.
doesn't really make sense for fixed-width. Use alternative method
clone(FixedWidthFields) . |
FixedWidthParserSettings |
clone(FixedWidthFields fields)
Clones this configuration object to reuse most user-provided settings.
|
protected void |
configureFromAnnotations(Class<?> beanClass)
Configures the parser based on the annotations provided in a given class
|
protected FixedWidthFormat |
createDefaultFormat()
Returns the default FixedWidthFormat configured to handle Fixed-Width inputs
|
int |
getMaxCharsPerColumn()
The maximum number of characters allowed for any given value being written/read.
|
int |
getMaxColumns()
Returns the hard limit of how many columns a record can have (defaults to a maximum of 512).
|
boolean |
getRecordEndsOnNewline()
Indicates whether or not a record is considered parsed when a newline is reached.
|
boolean |
getSkipTrailingCharsUntilNewline()
Indicates whether or not any trailing characters beyond the record's length should be skipped until the newline is reached (defaults to false)
|
boolean |
getUseDefaultPaddingForHeaders()
Indicates whether headers should be parsed using the default padding specified in
FixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (in FixedWidthFields.setPadding(char, int...) )
Defaults to true |
protected CharAppender |
newCharAppender()
Returns an instance of CharAppender with the configured limit of maximum characters per column and, default value used to represent a null value (when the String parsed from the input is empty), and the padding character to handle unwritten positions
|
void |
setRecordEndsOnNewline(boolean recordEndsOnNewline)
Defines whether or not a record is considered parsed when a newline is reached.
|
void |
setSkipTrailingCharsUntilNewline(boolean skipTrailingCharsUntilNewline)
Defines whether or not any trailing characters beyond the record's length should be skipped until the newline is reached (defaults to false)
|
void |
setUseDefaultPaddingForHeaders(boolean useDefaultPaddingForHeaders)
Defines whether headers should be parsed using the default padding specified in
FixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (in FixedWidthFields.setPadding(char, int...) ) |
clearInputSpecificSettings, getInputBufferSize, getNumberOfRecordsToRead, getNumberOfRowsToSkip, getProcessor, getReadInputOnSeparateThread, getRowProcessor, isColumnReorderingEnabled, isCommentCollectionEnabled, isHeaderExtractionEnabled, isLineSeparatorDetectionEnabled, newCharInputReader, setColumnReorderingEnabled, setCommentCollectionEnabled, setHeaderExtractionEnabled, setInputBufferSize, setLineSeparatorDetectionEnabled, setNumberOfRecordsToRead, setNumberOfRowsToSkip, setProcessor, setReadInputOnSeparateThread, setRowProcessor
excludeFields, excludeFields, excludeIndexes, getErrorContentLength, getFormat, getHeaders, getIgnoreLeadingWhitespaces, getIgnoreTrailingWhitespaces, 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
protected boolean skipTrailingCharsUntilNewline
protected boolean recordEndsOnNewline
public FixedWidthParserSettings(FixedWidthFields fieldLengths)
This must provided using an instance of FixedWidthFields
.
fieldLengths
- the instance of FixedWidthFields
which provides the lengths of each field in the fixed-width records to be parsedFixedWidthFields
public FixedWidthParserSettings()
addFormatForLookahead(String, FixedWidthFields)
, addFormatForLookbehind(String, FixedWidthFields)
public boolean getSkipTrailingCharsUntilNewline()
For example, if the record length is 5, but the row contains "12345678\n", then the portion containing "678\n" will be discarded and not considered part of the next record
public void setSkipTrailingCharsUntilNewline(boolean skipTrailingCharsUntilNewline)
For example, if the record length is 5, but the row contains "12345678\n", then the portion containing "678\n" will be discarded and not considered part of the next record
skipTrailingCharsUntilNewline
- a flag indicating if any trailing characters beyond the record's length should be skipped until the newline is reachedpublic boolean getRecordEndsOnNewline()
recordEndsOnNewline
is set to true: the first value will be read as 12 and the second 3456recordEndsOnNewline
is set to false: the first value will be read as 12\n3 and the second 456Defaults to false
public void setRecordEndsOnNewline(boolean recordEndsOnNewline)
recordEndsOnNewline
is set to true: the first value will be read as 12 and the second 3456recordEndsOnNewline
is set to false: the first value will be read as 12\n3 and the second 456recordEndsOnNewline
- a flag indicating whether or not a record is considered parsed when a newline is reachedprotected FixedWidthFormat createDefaultFormat()
createDefaultFormat
in class CommonSettings<FixedWidthFormat>
protected CharAppender newCharAppender()
This overrides the parent implementation to create a CharAppender capable of handling padding characters that represent unwritten positions.
newCharAppender
in class CommonParserSettings<FixedWidthFormat>
public int getMaxCharsPerColumn()
This overrides the parent implementation and calculates the absolute minimum number of characters required to store the values of a record
If the sum of all field lengths is greater than the configured maximum number of characters per column, the calculated amount will be returned.
getMaxCharsPerColumn
in class CommonSettings<FixedWidthFormat>
public int getMaxColumns()
This overrides the parent implementation and calculates the absolute minimum number of columns required to store the values of a record
If the sum of all fields is greater than the configured maximum number columns, the calculated amount will be returned.
getMaxColumns
in class CommonSettings<FixedWidthFormat>
public void addFormatForLookahead(String lookahead, FixedWidthFields lengths)
lookahead
- the lookahead value that when found in the input,
will notify the parser to switch to a new record format, with different field lengthslengths
- the field lengths of the record format identified by the given lookahead symbol.public void addFormatForLookbehind(String lookbehind, FixedWidthFields lengths)
lookbehind
- the lookbehind value that when found in the previous input row,
will notify the parser to switch to a new record format, with different field lengthslengths
- the field lengths of the record format identified by the given lookbehind symbol.public boolean getUseDefaultPaddingForHeaders()
FixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (in FixedWidthFields.setPadding(char, int...)
)
Defaults to true
true
if the default padding is to be used when reading headers, otherwise false
public void setUseDefaultPaddingForHeaders(boolean useDefaultPaddingForHeaders)
FixedWidthFormat.getPadding()
instead of any custom padding associated with a given field (in FixedWidthFields.setPadding(char, int...)
)useDefaultPaddingForHeaders
- flag indicating whether the default padding is to be used when parsing headersprotected void configureFromAnnotations(Class<?> beanClass)
CommonParserSettings
configureFromAnnotations
in class CommonParserSettings<FixedWidthFormat>
beanClass
- the classes whose annotations will be processed to derive configurations for parsingprotected void addConfiguration(Map<String,Object> out)
addConfiguration
in class CommonParserSettings<FixedWidthFormat>
public final FixedWidthParserSettings clone()
clone
in class CommonParserSettings<FixedWidthFormat>
@Deprecated protected final FixedWidthParserSettings clone(boolean clearInputSpecificSettings)
clone(FixedWidthFields)
.clone
in class CommonParserSettings<FixedWidthFormat>
clearInputSpecificSettings
- flag indicating whether to clear settings that are likely to be associated with a given input.public final FixedWidthParserSettings clone(FixedWidthFields fields)
clone()
.fields
- the fixed-width field configuration to be used by the cloned settings object.Copyright © 2017 uniVocity Software Pty Ltd. All rights reserved.