public final class CsvParser extends AbstractParser<CsvParserSettings>
CsvFormat
,
CsvParserSettings
,
CsvWriter
,
AbstractParser
Modifier and Type | Field and Description |
---|---|
private boolean |
backToDelimiter |
private char |
delimiter |
private char[] |
delimiters |
private boolean |
doNotEscapeUnquotedValues |
private java.lang.String |
emptyValue |
private char |
escapeEscape |
private boolean |
keepEscape |
private boolean |
keepQuotes |
private int |
match |
private int |
maxColumnLength |
private char[] |
multiDelimiter |
private char |
newLine |
private boolean |
normalizeLineEndingsInQuotes |
private java.lang.String |
nullValue |
private boolean |
parseUnescapedQuotes |
private boolean |
parseUnescapedQuotesUntilDelimiter |
private char |
prev |
private char |
quote |
private char |
quoteEscape |
private UnescapedQuoteHandling |
quoteHandling |
private boolean |
trimQuotedLeading |
private boolean |
trimQuotedTrailing |
private boolean |
unescaped |
private DefaultCharAppender |
whitespaceAppender |
ch, comment, comments, context, ignoreLeadingWhitespace, ignoreTrailingWhitespace, input, lastComment, output, processor, settings, whitespaceRangeStart
Constructor and Description |
---|
CsvParser(CsvParserSettings settings)
The CsvParser supports all settings provided by
CsvParserSettings , and requires this configuration to be properly initialized. |
Modifier and Type | Method and Description |
---|---|
private void |
appendUntilMultiDelimiter() |
protected boolean |
consumeValueOnEOF()
Allows the parser implementation to handle any value that was being consumed when the end of the input was reached
|
CsvFormat |
getDetectedFormat()
Returns the CSV format detected when one of the following settings is enabled:
CommonParserSettings.isLineSeparatorDetectionEnabled()
CsvParserSettings.isDelimiterDetectionEnabled()
CsvParserSettings.isQuoteDetectionEnabled()
The detected format will be available once the parsing process is initialized (i.e. |
protected InputAnalysisProcess |
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 |
handleUnescapedQuote() |
private void |
handleUnescapedQuoteInValue() |
private void |
handleValueSkipping(boolean quoted) |
private boolean |
matchDelimiter() |
private boolean |
matchDelimiterAfterQuote() |
private int |
nextDelimiter() |
private void |
parseMultiDelimiterRecord() |
private void |
parseQuotedValue() |
private void |
parseQuotedValueMultiDelimiter() |
protected void |
parseRecord()
Parser-specific implementation for reading a single record from the input.
|
private void |
parseSingleDelimiterRecord() |
private void |
parseValueProcessingEscape() |
private void |
parseValueProcessingEscapeMultiDelimiter() |
private void |
processQuoteEscape() |
private void |
saveMatchingCharacters() |
private void |
skipValue() |
private void |
skipWhitespace() |
void |
updateFormat(CsvFormat format)
Allows changing the format of the input on the fly.
|
beginParsing, beginParsing, beginParsing, beginParsing, beginParsing, beginParsing, beginParsing, createParsingContext, getContext, 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
private boolean parseUnescapedQuotes
private boolean parseUnescapedQuotesUntilDelimiter
private boolean backToDelimiter
private final boolean doNotEscapeUnquotedValues
private final boolean keepEscape
private final boolean keepQuotes
private boolean unescaped
private char prev
private char delimiter
private char[] multiDelimiter
private char quote
private char quoteEscape
private char escapeEscape
private char newLine
private final DefaultCharAppender whitespaceAppender
private final boolean normalizeLineEndingsInQuotes
private UnescapedQuoteHandling quoteHandling
private final java.lang.String nullValue
private final int maxColumnLength
private final java.lang.String emptyValue
private final boolean trimQuotedLeading
private final boolean trimQuotedTrailing
private char[] delimiters
private int match
public CsvParser(CsvParserSettings settings)
CsvParserSettings
, and requires this configuration to be properly initialized.settings
- the parser configurationprotected final void parseRecord()
AbstractParser
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 of
AbstractParser.parseRecord()
will perform the following steps:
CharAppender
) so the next call to output.appender.append(ch) will be store the character of the next parsed value Once the AbstractParser.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.
parseRecord
in class AbstractParser<CsvParserSettings>
CharInputReader
,
CharAppender
,
ParserOutput
,
TextParsingException
,
RowProcessor
private final void parseSingleDelimiterRecord()
private void skipValue()
private void handleValueSkipping(boolean quoted)
private void handleUnescapedQuoteInValue()
private int nextDelimiter()
private boolean handleUnescapedQuote()
private void processQuoteEscape()
private void parseValueProcessingEscape()
private void parseQuotedValue()
protected final InputAnalysisProcess getInputAnalysisProcess()
AbstractParser
getInputAnalysisProcess
in class AbstractParser<CsvParserSettings>
InputAnalysisProcess
. By default, null
is returned and no special input analysis will be performed.public final CsvFormat getDetectedFormat()
CommonParserSettings.isLineSeparatorDetectionEnabled()
CsvParserSettings.isDelimiterDetectionEnabled()
CsvParserSettings.isQuoteDetectionEnabled()
runs
.null
if no detection has been enabled or if the parsing process has not been started yet.protected final boolean consumeValueOnEOF()
AbstractParser
consumeValueOnEOF
in class AbstractParser<CsvParserSettings>
public final void updateFormat(CsvFormat format)
format
- the new format to use.private void skipWhitespace()
private void saveMatchingCharacters()
private boolean matchDelimiter()
private boolean matchDelimiterAfterQuote()
private void parseMultiDelimiterRecord()
private void appendUntilMultiDelimiter()
private void parseQuotedValueMultiDelimiter()
private void parseValueProcessingEscapeMultiDelimiter()