com.univocity.parsers.fixed
Class FixedWidthParserSettings

java.lang.Object
  extended by com.univocity.parsers.common.CommonSettings<F>
      extended by com.univocity.parsers.common.CommonParserSettings<FixedWidthFormat>
          extended by com.univocity.parsers.fixed.FixedWidthParserSettings

public class FixedWidthParserSettings
extends CommonParserSettings<FixedWidthFormat>

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 - parsers@univocity.com
See Also:
FixedWidthParser, FixedWidthFormat, FixedWidthFields, CommonParserSettings

Field Summary
protected  boolean recordEndsOnNewline
           
protected  boolean skipTrailingCharsUntilNewline
           
 
Constructor Summary
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.
 
Method Summary
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.
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...))
 
Methods inherited from class com.univocity.parsers.common.CommonParserSettings
getInputBufferSize, getNumberOfRecordsToRead, getNumberOfRowsToSkip, getProcessor, getReadInputOnSeparateThread, getRowProcessor, isColumnReorderingEnabled, isCommentCollectionEnabled, isHeaderExtractionEnabled, isLineSeparatorDetectionEnabled, setColumnReorderingEnabled, setCommentCollectionEnabled, setHeaderExtractionEnabled, setInputBufferSize, setLineSeparatorDetectionEnabled, setNumberOfRecordsToRead, setNumberOfRowsToSkip, setProcessor, setReadInputOnSeparateThread, setRowProcessor
 
Methods inherited from class com.univocity.parsers.common.CommonSettings
excludeFields, excludeFields, excludeIndexes, getErrorContentLength, getFormat, getHeaders, getIgnoreLeadingWhitespaces, getIgnoreTrailingWhitespaces, getNullValue, getProcessorErrorHandler, getRowProcessorErrorHandler, getSkipEmptyLines, isAutoConfigurationEnabled, isProcessorErrorHandlerDefined, selectFields, selectFields, selectIndexes, setAutoConfigurationEnabled, setErrorContentLength, setFormat, setHeaders, setIgnoreLeadingWhitespaces, setIgnoreTrailingWhitespaces, setMaxCharsPerColumn, setMaxColumns, setNullValue, setProcessorErrorHandler, setRowProcessorErrorHandler, setSkipEmptyLines, toString, trimValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

skipTrailingCharsUntilNewline

protected boolean skipTrailingCharsUntilNewline

recordEndsOnNewline

protected boolean recordEndsOnNewline
Constructor Detail

FixedWidthParserSettings

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 - the instance of FixedWidthFields which provides the lengths of each field in the fixed-width records to be parsed
See Also:
FixedWidthFields

FixedWidthParserSettings

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

getSkipTrailingCharsUntilNewline

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:
returns true if any trailing characters beyond the record's length should be skipped until the newline is reached, false otherwise

setSkipTrailingCharsUntilNewline

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 - a flag indicating if any trailing characters beyond the record's length should be skipped until the newline is reached

getRecordEndsOnNewline

public boolean getRecordEndsOnNewline()
Indicates whether or not a record is considered parsed when a newline is reached. Examples:

Defaults to false

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

setRecordEndsOnNewline

public void setRecordEndsOnNewline(boolean recordEndsOnNewline)
Defines whether or not a record is considered parsed when a newline is reached. Examples:

Parameters:
recordEndsOnNewline - a flag indicating whether or not a record is considered parsed when a newline is reached

createDefaultFormat

protected FixedWidthFormat createDefaultFormat()
Returns the default FixedWidthFormat configured to handle Fixed-Width inputs

Specified by:
createDefaultFormat in class CommonSettings<FixedWidthFormat>
Returns:
and instance of FixedWidthFormat configured to handle Fixed-Width inputs

newCharAppender

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

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

Overrides:
newCharAppender in class CommonParserSettings<FixedWidthFormat>
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

getMaxCharsPerColumn

public int 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.

Overrides:
getMaxCharsPerColumn in class CommonSettings<FixedWidthFormat>
Returns:
The maximum number of characters allowed for any given value being written/read

getMaxColumns

public int 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.

Overrides:
getMaxColumns in class CommonSettings<FixedWidthFormat>
Returns:
The maximum number of columns a record can have.

addFormatForLookahead

public void addFormatForLookahead(String lookahead,
                                  FixedWidthFields lengths)
Defines the format of records identified by a lookahead symbol.

Parameters:
lookahead - 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 - the field lengths of the record format identified by the given lookahead symbol.

addFormatForLookbehind

public void addFormatForLookbehind(String lookbehind,
                                   FixedWidthFields lengths)
Defines the format of records identified by a lookbehind symbol.

Parameters:
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 lengths
lengths - the field lengths of the record format identified by the given lookbehind symbol.

getUseDefaultPaddingForHeaders

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

setUseDefaultPaddingForHeaders

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

addConfiguration

protected void addConfiguration(Map<String,Object> out)
Overrides:
addConfiguration in class CommonParserSettings<FixedWidthFormat>


Copyright © 2016 uniVocity Software Pty Ltd. All rights reserved.