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

public final Class CsvParser

extends AbstractParser<CsvParserSettings>
Class Inheritance
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.input.EOFException, com.univocity.parsers.common.input.*, java.io.*

A very fast CSV parser implementation.
Author
Univocity Software Pty Ltd - [email protected]
See Also
CsvFormat, CsvParserSettings, CsvWriter, AbstractParser

Field Summary

Modifier and TypeField and Description
private boolean
private char
private char[]
private final boolean
private final String
private char
private int
private final boolean
private final boolean
private int
private final int
private char[]
private char
private final boolean
private final String
private boolean
private boolean
private char
private char
private char
private UnescapedQuoteHandling
private final boolean
private final boolean
private boolean
private final DefaultCharAppender
Inherited from com.univocity.parsers.common.AbstractParser:
chcommentcommentscontextignoreLeadingWhitespaceignoreTrailingWhitespaceinputlastCommentoutputprocessorsettingswhitespaceRangeStart

Constructor Summary

AccessConstructor and Description
public
CsvParser(CsvParserSettings
the parser configuration
settings
)

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

Method Summary

Modifier and TypeMethod and Description
private void
protected final boolean
consumeValueOnEOF()

Overrides com.univocity.parsers.common.AbstractParser.consumeValueOnEOF.

Allows the parser implementation to handle any value that was being consumed when the end of the input was reached
public final CsvFormat

Returns:

the detected CSV format, or null if no detection has been enabled or if the parsing process has not been started yet.
getDetectedFormat
()

Returns the CSV format detected when one of the following settings is enabled:

protected final InputAnalysisProcess
getInputAnalysisProcess()

Overrides com.univocity.parsers.common.AbstractParser.getInputAnalysisProcess.

Allows the parser implementation to traverse the input buffer before the parsing process starts, in order to enable automatic configuration and discovery of data formats.
private boolean
private void
private void
handleValueSkipping(boolean quoted)

private boolean
private boolean
private int
private void
private void
private void
protected final void
parseRecord()

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

Parser-specific implementation for reading a single record from the input.
private final void
private void
private void
private void
private void
private void
private void
public final void
updateFormat(CsvFormat
the new format to use.
format
)

Allows changing the format of the input on the fly.

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

Field Detail

backToDelimiterback to summary
private boolean backToDelimiter
delimiterback to summary
private char delimiter
delimitersback to summary
private char[] delimiters
doNotEscapeUnquotedValuesback to summary
private final boolean doNotEscapeUnquotedValues
emptyValueback to summary
private final String emptyValue
escapeEscapeback to summary
private char escapeEscape
formatDetectorRowSampleCountback to summary
private int formatDetectorRowSampleCount
keepEscapeback to summary
private final boolean keepEscape
keepQuotesback to summary
private final boolean keepQuotes
matchback to summary
private int match
maxColumnLengthback to summary
private final int maxColumnLength
multiDelimiterback to summary
private char[] multiDelimiter
newLineback to summary
private char newLine
normalizeLineEndingsInQuotesback to summary
private final boolean normalizeLineEndingsInQuotes
nullValueback to summary
private final String nullValue
parseUnescapedQuotesback to summary
private boolean parseUnescapedQuotes
parseUnescapedQuotesUntilDelimiterback to summary
private boolean parseUnescapedQuotesUntilDelimiter
prevback to summary
private char prev
quoteback to summary
private char quote
quoteEscapeback to summary
private char quoteEscape
quoteHandlingback to summary
private UnescapedQuoteHandling quoteHandling
trimQuotedLeadingback to summary
private final boolean trimQuotedLeading
trimQuotedTrailingback to summary
private final boolean trimQuotedTrailing
unescapedback to summary
private boolean unescaped
whitespaceAppenderback to summary
private final DefaultCharAppender whitespaceAppender

Constructor Detail

CsvParserback to summary
public CsvParser(CsvParserSettings settings)

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

Parameters
settings:CsvParserSettings

the parser configuration

Method Detail

appendUntilMultiDelimiterback to summary
private void appendUntilMultiDelimiter()
consumeValueOnEOFback to summary
protected final boolean consumeValueOnEOF()

Overrides com.univocity.parsers.common.AbstractParser.consumeValueOnEOF.

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

Allows the parser implementation to handle any value that was being consumed when the end of the input was reached

Returns:boolean

a flag indicating whether the parser was processing a value when the end of the input was reached.

Annotations
@Override
getDetectedFormatback to summary
public final CsvFormat getDetectedFormat()

Returns the CSV format detected when one of the following settings is enabled:

The detected format will be available once the parsing process is initialized (i.e. when runs.
Returns:CsvFormat

the detected CSV format, or null if no detection has been enabled or if the parsing process has not been started yet.

getInputAnalysisProcessback to summary
protected final InputAnalysisProcess getInputAnalysisProcess()

Overrides com.univocity.parsers.common.AbstractParser.getInputAnalysisProcess.

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

Allows the parser implementation to traverse the input buffer before the parsing process starts, in order to enable automatic configuration and discovery of data formats.

Returns:InputAnalysisProcess

a custom implementation of InputAnalysisProcess. By default, null is returned and no special input analysis will be performed.

Annotations
@Override
handleUnescapedQuoteback to summary
private boolean handleUnescapedQuote()
handleUnescapedQuoteInValueback to summary
private void handleUnescapedQuoteInValue()
handleValueSkippingback to summary
private void handleValueSkipping(boolean quoted)
matchDelimiterback to summary
private boolean matchDelimiter()
matchDelimiterAfterQuoteback to summary
private boolean matchDelimiterAfterQuote()
nextDelimiterback to summary
private int nextDelimiter()
parseMultiDelimiterRecordback to summary
private void parseMultiDelimiterRecord()
parseQuotedValueback to summary
private void parseQuotedValue()
parseQuotedValueMultiDelimiterback to summary
private void parseQuotedValueMultiDelimiter()
parseRecordback to summary
protected final 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
parseSingleDelimiterRecordback to summary
private final void parseSingleDelimiterRecord()
parseValueProcessingEscapeback to summary
private void parseValueProcessingEscape()
parseValueProcessingEscapeMultiDelimiterback to summary
private void parseValueProcessingEscapeMultiDelimiter()
processQuoteEscapeback to summary
private void processQuoteEscape()
saveMatchingCharactersback to summary
private void saveMatchingCharacters()
skipValueback to summary
private void skipValue()
skipWhitespaceback to summary
private void skipWhitespace()
updateFormatback to summary
public final void updateFormat(CsvFormat format)

Allows changing the format of the input on the fly.

Parameters
format:CsvFormat

the new format to use.