Class FixedWidthParser
- java.lang.Object
-
- com.univocity.parsers.common.AbstractParser<FixedWidthParserSettings>
-
- com.univocity.parsers.fixed.FixedWidthParser
-
public class FixedWidthParser extends AbstractParser<FixedWidthParserSettings>
A fast and flexible fixed-with parser implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private FieldAlignmentalignmentprivate FieldAlignment[]alignmentsprivate chardefaultPaddingprivate boolean[]ignoreprivate booleaninitializeLookaheadInputprivate booleankeepPaddingprivate java.lang.Boolean[]keepPaddingFlagsprivate intlengthprivate int[]lengthsprivate Lookup[]lookaheadFormatsprivate LookaheadCharInputReaderlookaheadInputprivate LookuplookbehindFormatprivate Lookup[]lookbehindFormatsprivate LookuplookupFormatprivate intmaxLookupLengthprivate charnewLineprivate charpaddingprivate char[]paddingsprivate booleanrecordEndsOnNewLineprivate FieldAlignment[]rootAlignmentsprivate boolean[]rootIgnoreprivate java.lang.Boolean[]rootKeepPaddingFlagsprivate int[]rootLengthsprivate char[]rootPaddingsprivate booleanskipEmptyLinesprivate booleanskipToNewLineprivate booleanuseDefaultPaddingprivate charwildcard-
Fields inherited from class com.univocity.parsers.common.AbstractParser
ch, comment, comments, context, ignoreLeadingWhitespace, ignoreTrailingWhitespace, input, lastComment, output, processor, settings, whitespaceRangeStart
-
-
Constructor Summary
Constructors Constructor Description FixedWidthParser(FixedWidthParserSettings settings)The FixedWidthParser supports all settings provided byFixedWidthParserSettings, and requires this configuration to be properly initialized.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ParsingContextcreateParsingContext()protected voidparseRecord()Parser-specific implementation for reading a single record from the input.private voidreadValue(boolean ignorePadding)private voidreadValueUntilNewLine(boolean ignorePadding)private voidskipPadding(boolean lastFieldOfRecord)private voidskipToNewLine()private voidskipWhitespace(boolean lastFieldOfRecord, boolean ignorePadding)-
Methods inherited from class com.univocity.parsers.common.AbstractParser
beginParsing, beginParsing, beginParsing, beginParsing, beginParsing, beginParsing, beginParsing, consumeValueOnEOF, getContext, getInputAnalysisProcess, getRecordMetadata, inComment, initialize, iterate, iterate, iterate, iterate, iterate, iterate, iterate, iterateRecords, iterateRecords, iterateRecords, iterateRecords, iterateRecords, iterateRecords, iterateRecords, parse, parse, parse, parse, parse, parse, parse, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAll, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseAllRecords, parseLine, parseNext, parseNextRecord, parseRecord, processComment, reloadHeaders, stopParsing
-
-
-
-
Field Detail
-
lengths
private int[] lengths
-
rootLengths
private int[] rootLengths
-
ignore
private boolean[] ignore
-
rootIgnore
private boolean[] rootIgnore
-
alignments
private FieldAlignment[] alignments
-
rootAlignments
private FieldAlignment[] rootAlignments
-
paddings
private char[] paddings
-
rootPaddings
private char[] rootPaddings
-
keepPaddingFlags
private java.lang.Boolean[] keepPaddingFlags
-
rootKeepPaddingFlags
private java.lang.Boolean[] rootKeepPaddingFlags
-
lookaheadFormats
private final Lookup[] lookaheadFormats
-
lookbehindFormats
private final Lookup[] lookbehindFormats
-
lookupFormat
private Lookup lookupFormat
-
lookbehindFormat
private Lookup lookbehindFormat
-
maxLookupLength
private int maxLookupLength
-
skipToNewLine
private final boolean skipToNewLine
-
recordEndsOnNewLine
private final boolean recordEndsOnNewLine
-
skipEmptyLines
private final boolean skipEmptyLines
-
keepPadding
private final boolean keepPadding
-
useDefaultPadding
private boolean useDefaultPadding
-
defaultPadding
private final char defaultPadding
-
padding
private char padding
-
alignment
private FieldAlignment alignment
-
newLine
private final char newLine
-
length
private int length
-
initializeLookaheadInput
private boolean initializeLookaheadInput
-
lookaheadInput
private LookaheadCharInputReader lookaheadInput
-
wildcard
private final char wildcard
-
-
Constructor Detail
-
FixedWidthParser
public FixedWidthParser(FixedWidthParserSettings settings)
The FixedWidthParser supports all settings provided byFixedWidthParserSettings, and requires this configuration to be properly initialized.- Parameters:
settings- the parser configuration
-
-
Method Detail
-
createParsingContext
protected ParsingContext createParsingContext()
- Overrides:
createParsingContextin classAbstractParser<FixedWidthParserSettings>
-
parseRecord
protected void parseRecord()
Description copied from class:AbstractParserParser-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
AbstractParser.parseRecord(). In general, an implementation ofAbstractParser.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
AbstractParser.parseRecord()returns, the AbstractParser takes over and handles the information (generally, reorganizing it and passing it on to aRowProcessor).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
TextParsingExceptionwill be thrown and all resources in use will be closed automatically unlessCommonParserSettings.isAutoClosingEnabled()evaluates tofalse. The exception should contain the cause and more information about where in the input the error happened.- Specified by:
parseRecordin classAbstractParser<FixedWidthParserSettings>- See Also:
CharInputReader,CharAppender,ParserOutput,TextParsingException,RowProcessor
-
skipToNewLine
private void skipToNewLine()
-
skipPadding
private void skipPadding(boolean lastFieldOfRecord)
-
skipWhitespace
private void skipWhitespace(boolean lastFieldOfRecord, boolean ignorePadding)
-
readValueUntilNewLine
private void readValueUntilNewLine(boolean ignorePadding)
-
readValue
private void readValue(boolean ignorePadding)
-
-