Top Description Fields Constructors Methods
com.univocity.parsers.fixed

public Class FixedWidthParserSettings

extends CommonParserSettings<FixedWidthFormat>
Class Inheritance
Imports
com.univocity.parsers.annotations.*, com.univocity.parsers.annotations.helpers.*, com.univocity.parsers.common.*, com.univocity.parsers.common.input.*, java.util.*

This is the configuration class used by the Fixed-Width parser (FixedWidthParser)

In addition to the configuration options provided by CommonParserSettings, the FixedWidthParserSettings include:

The FixedWidthParserSettings need 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 - [email protected]
See Also
com.univocity.parsers.fixed.FixedWidthParser, com.univocity.parsers.fixed.FixedWidthFormat, FixedWidthFields, com.univocity.parsers.common.CommonParserSettings

Field Summary

Modifier and TypeField and Description
private FixedWidthFields
private boolean
private Map<String, FixedWidthFields>
private Map<String, FixedWidthFields>
protected boolean
protected boolean
private boolean
Inherited from com.univocity.parsers.common.CommonParserSettings:
headerExtractionEnabled

Constructor Summary

AccessConstructor and Description
public
FixedWidthParserSettings(FixedWidthFields
the instance of FixedWidthFields which provides the lengths of each field in the fixed-width records to be parsed
fieldLengths
)

You can only create an instance of this class by providing a definition of the field lengths of each record in the input.

public
FixedWidthParserSettings()

Creates a basic configuration object for the Fixed-Width parser with no field length configuration.

Method Summary

Modifier and TypeMethod and Description
protected void
public void
addFormatForLookahead(String
the lookahead value that when found in the input, will notify the parser to switch to a new record format, with different field lengths
lookahead
,
FixedWidthFields
the field lengths of the record format identified by the given lookahead symbol.
lengths
)

Defines the format of records identified by a lookahead symbol.

public void
addFormatForLookbehind(String
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 lengths
lookbehind
,
FixedWidthFields
the field lengths of the record format identified by the given lookbehind symbol.
lengths
)

Defines the format of records identified by a lookbehind symbol.

private int[]
public final FixedWidthParserSettings

Returns:

a copy of all configurations applied to the current instance.
clone
()

Overrides com.univocity.parsers.common.CommonParserSettings.clone.

Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.
protected final FixedWidthParserSettings

Returns:

a copy of all configurations applied to the current instance.
clone
(boolean
flag indicating whether to clear settings that are likely to be associated with a given input.
clearInputSpecificSettings
)

Overrides com.univocity.parsers.common.CommonParserSettings.clone.

Deprecated doesn't really make sense for fixed-width.
Clones this configuration object to reuse most user-provided settings.
public final FixedWidthParserSettings

Returns:

a copy of the general configurations applied to the current instance.
clone
(FixedWidthFields
the fixed-width field configuration to be used by the cloned settings object.
fields
)

Clones this configuration object to reuse most user-provided settings.

private FixedWidthParserSettings
clone(boolean clearInputSpecificSettings, FixedWidthFields fields)

protected void
configureFromAnnotations(Class<?>
the classes whose annotations will be processed to derive configurations for parsing
beanClass
)

Overrides com.univocity.parsers.common.CommonParserSettings.configureFromAnnotations.

Configures the parser based on the annotations provided in a given class
protected FixedWidthFormat

Returns:

and instance of FixedWidthFormat configured to handle Fixed-Width inputs
createDefaultFormat
()

Implements abstract com.univocity.parsers.common.CommonSettings.createDefaultFormat.

Returns the default FixedWidthFormat configured to handle Fixed-Width inputs
pack-priv int[]
pack-priv FieldAlignment[]

Returns:

the sequence of alignments to consider for each field of each record.
getFieldAlignments
()

Returns the sequence of alignments to consider for each field of each record.

pack-priv int[]

Returns:

the sequence of lengths to be read by the parser to form a record.
getFieldLengths
()

Returns the sequence of lengths to be read by the parser to form a record.

pack-priv char[]

Returns:

the sequence of paddings used by each field of each record.
getFieldPaddings
()

Returns the sequence of paddings used by each field of each record.

pack-priv boolean[]

Returns:

the sequence of fields to ignore.
getFieldsToIgnore
()

Returns the sequence of fields to ignore.

public final boolean

Returns:

flag indicating the padding character should be kept in the parsed value
getKeepPadding
()

Indicate the padding character should be kept in the parsed value (defaults to false) This setting can be overridden for individual fields through FixedWidthFields#stripPaddingFrom(String, String...) and FixedWidthFields#keepPaddingOn(String, String...)

pack-priv Boolean[]

Returns:

the sequence that have an explicit 'keepPadding' flag.
getKeepPaddingFlags
()

Returns the sequence of fields whose padding character must/must not be retained in the parsed value

pack-priv Lookup[]
pack-priv Lookup[]
public int

Returns:

The maximum number of characters allowed for any given value being written/read
getMaxCharsPerColumn
()

Overrides com.univocity.parsers.common.CommonSettings.getMaxCharsPerColumn.

The maximum number of characters allowed for any given value being written/read.
public int

Returns:

The maximum number of columns a record can have.
getMaxColumns
()

Overrides com.univocity.parsers.common.CommonSettings.getMaxColumns.

Returns the hard limit of how many columns a record can have (defaults to a maximum of 512).
public boolean

Returns:

true if a record should be considered parsed when a newline is reached; false otherwise
getRecordEndsOnNewline
()

Indicates whether or not a record is considered parsed when a newline is reached.

public boolean

Returns:

returns true if any trailing characters beyond the record's length should be skipped until the newline is reached, false otherwise
getSkipTrailingCharsUntilNewline
()

Indicates whether or not any trailing characters beyond the record's length should be skipped until the newline is reached (defaults to false)

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 boolean

Returns:

true if the default padding is to be used when reading headers, otherwise false
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

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
newCharAppender
()

Overrides com.univocity.parsers.common.CommonParserSettings.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

This overrides the parent implementation to create a CharAppender capable of handling padding characters that represent unwritten positions.

public final void
setKeepPadding(boolean
flag indicating the padding character should be kept in the parsed value
keepPadding
)

Configures the fixed-width parser to retain the padding character in any parsed values (defaults to false) This setting can be overridden for individual fields through FixedWidthFields#stripPaddingFrom(String, String...) and FixedWidthFields#keepPaddingOn(String, String...)

public void
setRecordEndsOnNewline(boolean
a flag indicating whether or not a record is considered parsed when a newline is reached
recordEndsOnNewline
)

Defines whether or not a record is considered parsed when a newline is reached.

public void
setSkipTrailingCharsUntilNewline(boolean
a flag indicating if any trailing characters beyond the record's length should be skipped until the newline is reached
skipTrailingCharsUntilNewline
)

Defines whether or not any trailing characters beyond the record's length should be skipped until the newline is reached (defaults to false)

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
setUseDefaultPaddingForHeaders(boolean
flag indicating whether the default padding is to be used when parsing headers
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...))

Inherited from com.univocity.parsers.common.CommonParserSettings:
addInputAnalysisProcessclearInputSpecificSettingsgetInputAnalysisProcessesgetInputBufferSizegetNumberOfRecordsToReadgetNumberOfRowsToSkipgetProcessorgetReadInputOnSeparateThreadgetRowProcessorisAutoClosingEnabledisColumnReorderingEnabledisCommentCollectionEnabledisCommentProcessingEnabledisHeaderExtractionEnabledisLineSeparatorDetectionEnablednewCharInputReadersetAutoClosingEnabledsetColumnReorderingEnabledsetCommentCollectionEnabledsetCommentProcessingEnabledsetHeaderExtractionEnabledsetInputBufferSizesetLineSeparatorDetectionEnabledsetNumberOfRecordsToReadsetNumberOfRowsToSkipsetProcessorsetReadInputOnSeparateThreadsetRowProcessor

Field Detail

fieldLengthsback to summary
private FixedWidthFields fieldLengths
keepPaddingback to summary
private boolean keepPadding
lookaheadFormatsback to summary
private Map<String, FixedWidthFields> lookaheadFormats
lookbehindFormatsback to summary
private Map<String, FixedWidthFields> lookbehindFormats
recordEndsOnNewlineback to summary
protected boolean recordEndsOnNewline
skipTrailingCharsUntilNewlineback to summary
protected boolean skipTrailingCharsUntilNewline
useDefaultPaddingForHeadersback to summary
private boolean useDefaultPaddingForHeaders

Constructor Detail

FixedWidthParserSettingsback to summary
public 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.

This must provided using an instance of FixedWidthFields.

Parameters
fieldLengths:FixedWidthFields

the instance of FixedWidthFields which provides the lengths of each field in the fixed-width records to be parsed

See Also
FixedWidthFields
FixedWidthParserSettingsback to summary
public FixedWidthParserSettings()

Creates a basic configuration object for the Fixed-Width parser with no field length configuration. This constructor is intended to be used when the record length varies depending of the input row. Refer to addFormatForLookahead(String, FixedWidthFields), addFormatForLookbehind(String, FixedWidthFields)

Method Detail

addConfigurationback to summary
protected void addConfiguration(Map<String, Object> out)

Overrides com.univocity.parsers.common.CommonParserSettings.addConfiguration.

Annotations
@Override
addFormatForLookaheadback to summary
public void addFormatForLookahead(String lookahead, FixedWidthFields lengths)

Defines the format of records identified by a lookahead symbol.

Parameters
lookahead:String

the lookahead value that when found in the input, will notify the parser to switch to a new record format, with different field lengths

lengths:FixedWidthFields

the field lengths of the record format identified by the given lookahead symbol.

addFormatForLookbehindback to summary
public void addFormatForLookbehind(String lookbehind, FixedWidthFields lengths)

Defines the format of records identified by a lookbehind symbol.

Parameters
lookbehind:String

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 lengths

lengths:FixedWidthFields

the field lengths of the record format identified by the given lookbehind symbol.

calculateMaxFieldLengthsback to summary
private int[] calculateMaxFieldLengths()
cloneback to summary
public final FixedWidthParserSettings clone()

Overrides com.univocity.parsers.common.CommonParserSettings.clone.

Clones this configuration object to reuse all user-provided settings, including the fixed-width field configuration.

Returns:FixedWidthParserSettings

a copy of all configurations applied to the current instance.

Annotations
@Override
cloneback to summary
protected final FixedWidthParserSettings clone(boolean clearInputSpecificSettings)

Overrides com.univocity.parsers.common.CommonParserSettings.clone.

Deprecated

doesn't really make sense for fixed-width. Use alternative method clone(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.

Parameters
clearInputSpecificSettings:boolean

Doc from com.univocity.parsers.common.CommonSettings.clone.

flag indicating whether to clear settings that are likely to be associated with a given input.

Returns:FixedWidthParserSettings

a copy of all configurations applied to the current instance.

Annotations
@Deprecated
cloneback to summary
public final FixedWidthParserSettings 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, use clone().

Parameters
fields:FixedWidthFields

the fixed-width field configuration to be used by the cloned settings object.

Returns:FixedWidthParserSettings

a copy of the general configurations applied to the current instance.

cloneback to summary
private FixedWidthParserSettings clone(boolean clearInputSpecificSettings, FixedWidthFields fields)
configureFromAnnotationsback to summary
protected void configureFromAnnotations(Class<?> beanClass)

Overrides com.univocity.parsers.common.CommonParserSettings.configureFromAnnotations.

Doc from com.univocity.parsers.common.CommonParserSettings.configureFromAnnotations.

Configures the parser based on the annotations provided in a given class

Parameters
beanClass:Class<?>

the classes whose annotations will be processed to derive configurations for parsing

Annotations
@Override
createDefaultFormatback to summary
protected FixedWidthFormat createDefaultFormat()

Implements abstract com.univocity.parsers.common.CommonSettings.createDefaultFormat.

Returns the default FixedWidthFormat configured to handle Fixed-Width inputs

Returns:FixedWidthFormat

and instance of FixedWidthFormat configured to handle Fixed-Width inputs

Annotations
@Override
getAllLengthsback to summary
pack-priv int[] getAllLengths()
getFieldAlignmentsback to summary
pack-priv FieldAlignment[] getFieldAlignments()

Returns the sequence of alignments to consider for each field of each record.

Returns:FieldAlignment[]

the sequence of alignments to consider for each field of each record.

getFieldLengthsback to summary
pack-priv int[] getFieldLengths()

Returns the sequence of lengths to be read by the parser to form a record.

Returns:int[]

the sequence of lengths to be read by the parser to form a record.

getFieldPaddingsback to summary
pack-priv char[] getFieldPaddings()

Returns the sequence of paddings used by each field of each record.

Returns:char[]

the sequence of paddings used by each field of each record.

getFieldsToIgnoreback to summary
pack-priv boolean[] getFieldsToIgnore()

Returns the sequence of fields to ignore.

Returns:boolean[]

the sequence of fields to ignore.

getKeepPaddingback to summary
public final boolean getKeepPadding()

Indicate the padding character should be kept in the parsed value (defaults to false) This setting can be overridden for individual fields through FixedWidthFields#stripPaddingFrom(String, String...) and FixedWidthFields#keepPaddingOn(String, String...)

Returns:boolean

flag indicating the padding character should be kept in the parsed value

getKeepPaddingFlagsback to summary
pack-priv Boolean[] getKeepPaddingFlags()

Returns the sequence of fields whose padding character must/must not be retained in the parsed value

Returns:Boolean[]

the sequence that have an explicit 'keepPadding' flag.

getLookaheadFormatsback to summary
pack-priv Lookup[] getLookaheadFormats()
getLookbehindFormatsback to summary
pack-priv Lookup[] getLookbehindFormats()
getMaxCharsPerColumnback to summary
public int getMaxCharsPerColumn()

Overrides com.univocity.parsers.common.CommonSettings.getMaxCharsPerColumn.

The maximum number of characters allowed for any given value being written/read. Used to avoid OutOfMemoryErrors (defaults to a minimum of 4096 characters).

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.

Returns:int

The maximum number of characters allowed for any given value being written/read

Annotations
@Override
getMaxColumnsback to summary
public int getMaxColumns()

Overrides com.univocity.parsers.common.CommonSettings.getMaxColumns.

Returns the hard limit of how many columns a record can have (defaults to a maximum of 512). You need this to avoid OutOfMemory errors in case of inputs that might be inconsistent with the format you are dealing with.

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.

Returns:int

The maximum number of columns a record can have.

Annotations
@Override
getRecordEndsOnNewlineback to summary
public boolean getRecordEndsOnNewline()

Indicates whether or not a record is considered parsed when a newline is reached. Examples:

defaults to false

Returns:boolean

true if a record should be considered parsed when a newline is reached; false otherwise

getSkipTrailingCharsUntilNewlineback to summary
public 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)

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

Returns:boolean

returns true if any trailing characters beyond the record's length should be skipped until the newline is reached, false otherwise

getUseDefaultPaddingForHeadersback to summary
public 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

Returns:boolean

true if the default padding is to be used when reading headers, otherwise false

newCharAppenderback to summary
protected CharAppender newCharAppender()

Overrides com.univocity.parsers.common.CommonParserSettings.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

This overrides the parent implementation to create a CharAppender capable of handling padding characters that represent unwritten positions.

Returns:CharAppender

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

Annotations
@Override
setKeepPaddingback to summary
public final void setKeepPadding(boolean keepPadding)

Configures the fixed-width parser to retain the padding character in any parsed values (defaults to false) This setting can be overridden for individual fields through FixedWidthFields#stripPaddingFrom(String, String...) and FixedWidthFields#keepPaddingOn(String, String...)

Parameters
keepPadding:boolean

flag indicating the padding character should be kept in the parsed value

setRecordEndsOnNewlineback to summary
public void setRecordEndsOnNewline(boolean recordEndsOnNewline)

Defines whether or not a record is considered parsed when a newline is reached. Examples:

Parameters
recordEndsOnNewline:boolean

a flag indicating whether or not a record is considered parsed when a newline is reached

setSkipTrailingCharsUntilNewlineback to summary
public 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)

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

Parameters
skipTrailingCharsUntilNewline:boolean

a flag indicating if any trailing characters beyond the record's length should be skipped until the newline is reached

setUseDefaultPaddingForHeadersback to summary
public 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...))

Parameters
useDefaultPaddingForHeaders:boolean

flag indicating whether the default padding is to be used when parsing headers