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

public Class FixedWidthParser

extends AbstractParser<FixedWidthParserSettings>
Class Inheritance
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.input.*, com.univocity.parsers.common.record.*

A fast and flexible fixed-with parser implementation.
Author
Univocity Software Pty Ltd - [email protected]
See Also
FixedWidthFormat, FixedWidthFields, FixedWidthParserSettings, FixedWidthWriter, AbstractParser

Field Summary

Modifier and TypeField and Description
private FieldAlignment
private FieldAlignment[]
private final char
private boolean[]
private boolean
private final boolean
private Boolean[]
private int
private int[]
private final Lookup[]
private LookaheadCharInputReader
private Lookup
private final Lookup[]
private Lookup
private int
private final char
private char
private char[]
private final boolean
private FieldAlignment[]
private boolean[]
private Boolean[]
private int[]
private char[]
private final boolean
private final boolean
private boolean
private final char
Inherited from com.univocity.parsers.common.AbstractParser:
chcommentcommentscontextignoreLeadingWhitespaceignoreTrailingWhitespaceinputlastCommentoutputprocessorsettingswhitespaceRangeStart

Constructor Summary

AccessConstructor and Description
public
FixedWidthParser(FixedWidthParserSettings
the parser configuration
settings
)

The FixedWidthParser supports all settings provided by FixedWidthParserSettings, and requires this configuration to be properly initialized.

Method Summary

Modifier and TypeMethod and Description
protected ParsingContext
protected void
parseRecord()

Implements abstract com.univocity.parsers.common.AbstractParser.parseRecord.

Parser-specific implementation for reading a single record from the input.
private void
readValue(boolean ignorePadding)

private void
readValueUntilNewLine(boolean ignorePadding)

private void
skipPadding(boolean lastFieldOfRecord)

private void
private void
skipWhitespace(boolean lastFieldOfRecord, boolean ignorePadding)

Inherited from com.univocity.parsers.common.AbstractParser:
beginParsingbeginParsingbeginParsingbeginParsingbeginParsingbeginParsingbeginParsingconsumeValueOnEOFgetContextgetInputAnalysisProcessgetRecordMetadatainCommentinitializeiterateiterateiterateiterateiterateiterateiterateiterateRecordsiterateRecordsiterateRecordsiterateRecordsiterateRecordsiterateRecordsiterateRecordsparseparseparseparseparseparseparseparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseAllRecordsparseLineparseNextparseNextRecordparseRecordprocessCommentreloadHeadersstopParsing

Field Detail

alignmentback to summary
private FieldAlignment alignment
alignmentsback to summary
private FieldAlignment[] alignments
defaultPaddingback to summary
private final char defaultPadding
ignoreback to summary
private boolean[] ignore
initializeLookaheadInputback to summary
private boolean initializeLookaheadInput
keepPaddingback to summary
private final boolean keepPadding
keepPaddingFlagsback to summary
private Boolean[] keepPaddingFlags
lengthback to summary
private int length
lengthsback to summary
private int[] lengths
lookaheadFormatsback to summary
private final Lookup[] lookaheadFormats
lookaheadInputback to summary
private LookaheadCharInputReader lookaheadInput
lookbehindFormatback to summary
private Lookup lookbehindFormat
lookbehindFormatsback to summary
private final Lookup[] lookbehindFormats
lookupFormatback to summary
private Lookup lookupFormat
maxLookupLengthback to summary
private int maxLookupLength
newLineback to summary
private final char newLine
paddingback to summary
private char padding
paddingsback to summary
private char[] paddings
recordEndsOnNewLineback to summary
private final boolean recordEndsOnNewLine
rootAlignmentsback to summary
private FieldAlignment[] rootAlignments
rootIgnoreback to summary
private boolean[] rootIgnore
rootKeepPaddingFlagsback to summary
private Boolean[] rootKeepPaddingFlags
rootLengthsback to summary
private int[] rootLengths
rootPaddingsback to summary
private char[] rootPaddings
skipEmptyLinesback to summary
private final boolean skipEmptyLines
skipToNewLineback to summary
private final boolean skipToNewLine
useDefaultPaddingback to summary
private boolean useDefaultPadding
wildcardback to summary
private final char wildcard

Constructor Detail

FixedWidthParserback to summary
public FixedWidthParser(FixedWidthParserSettings settings)

The FixedWidthParser supports all settings provided by FixedWidthParserSettings, and requires this configuration to be properly initialized.

Parameters
settings:FixedWidthParserSettings

the parser configuration

Method Detail

createParsingContextback to summary
protected ParsingContext createParsingContext()

Overrides com.univocity.parsers.common.AbstractParser.createParsingContext.

Annotations
@Override
parseRecordback to summary
protected void parseRecord()

Implements abstract com.univocity.parsers.common.AbstractParser.parseRecord.

Doc from com.univocity.parsers.common.AbstractParser.parseRecord.

Parser-specific implementation for reading a single record from the input.

The AbstractParser handles the initialization and processing of the input until it is ready to be parsed.

It then delegates the input to the parser-specific implementation defined by parseRecord(). In general, an implementation of AbstractParser#parseRecord() will perform the following steps:

  • Test the character stored in ch and take some action on it (e.g. is while (ch != '\n'){doSomething()})
  • Request more characters by calling ch = input.nextChar();
  • Append the desired characters to the output by executing, for example, output.appender.append(ch)
  • Notify a value of the record has been fully read by executing output.valueParsed(). This will clear the output appender (CharAppender) so the next call to output.appender.append(ch) will be store the character of the next parsed value
  • Rinse and repeat until all values of the record are parsed

Once the parseRecord() returns, the AbstractParser takes over and handles the information (generally, reorganizing it and passing it on to a RowProcessor).

After the record processing, the AbstractParser reads the next characters from the input, delegating control again to the parseRecord() implementation for processing of the next record.

This cycle repeats until the reading process is stopped by the user, the input is exhausted, or an error happens.

In case of errors, the unchecked exception TextParsingException will be thrown and all resources in use will be closed automatically unless CommonParserSettings#isAutoClosingEnabled() evaluates to false. The exception should contain the cause and more information about where in the input the error happened.

Annotations
@Override
readValueback to summary
private void readValue(boolean ignorePadding)
readValueUntilNewLineback to summary
private void readValueUntilNewLine(boolean ignorePadding)
skipPaddingback to summary
private void skipPadding(boolean lastFieldOfRecord)
skipToNewLineback to summary
private void skipToNewLine()
skipWhitespaceback to summary
private void skipWhitespace(boolean lastFieldOfRecord, boolean ignorePadding)