public class CsvParser
extends com.fasterxml.jackson.core.base.ParserMinimalBase
JsonParser implementation used to expose CSV documents
in form that allows other Jackson functionality to deal
with it.
Implementation is based on a state-machine that pulls information
using CsvDecoder.
| Modifier and Type | Class and Description |
|---|---|
static class |
CsvParser.Feature
Enumeration that defines all togglable features for CSV parsers
|
| Modifier and Type | Field and Description |
|---|---|
protected String |
_arraySeparator |
protected String |
_arrayValue
Contents of the cell, to be split into distinct array values.
|
protected int |
_arrayValueStart
Pointer to the first character of the next array value to return.
|
protected byte[] |
_binaryValue
We will hold on to decoded binary data, for duration of
current event, so that multiple calls to
getBinaryValue(com.fasterxml.jackson.core.Base64Variant) will not need to decode data more
than once. |
protected com.fasterxml.jackson.core.util.ByteArrayBuilder |
_byteArrayBuilder |
protected boolean |
_cfgEmptyStringAsNull |
protected int |
_columnCount
Number of columns defined by schema.
|
protected int |
_columnIndex
Index of the column we are exposing
|
protected String |
_currentName
Name of column that we exposed most recently, accessible after
JsonToken.FIELD_NAME as well as value tokens immediately
following field name. |
protected String |
_currentValue
String value for the current column, if accessed.
|
protected int |
_formatFeatures |
protected String |
_nullValue |
protected com.fasterxml.jackson.core.ObjectCodec |
_objectCodec
Codec used for data binding when (if) requested.
|
protected com.fasterxml.jackson.core.json.JsonReadContext |
_parsingContext
Information about parser context, context in which
the next token is to be parsed (root, array, object).
|
protected CsvDecoder |
_reader
Thing that actually reads the CSV content
|
protected CsvSchema |
_schema
Definition of columns being read.
|
protected int |
_state
Current logical state of the parser; one of
STATE_
constants. |
protected TextBuffer |
_textBuffer
Buffer that contains contents of all values after processing
of doubled-quotes, escaped characters.
|
protected static int |
STATE_DOC_END
State in which end marker is returned; either
null (if no array wrapping), or
JsonToken.END_ARRAY for wrapping. |
protected static int |
STATE_DOC_START
Initial state before anything is read from document.
|
protected static int |
STATE_IN_ARRAY
State in which a column value has been determined to be of
an array type, and will need to be split into multiple
values.
|
protected static int |
STATE_MISSING_NAME
State in which we should expose name token for a "missing column"
(for which placeholder `null` value is to be added as well);
see
CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS for details. |
protected static int |
STATE_MISSING_VALUE
State in which we should expose `null` value token as a value for
"missing" column;
see
CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS for details. |
protected static int |
STATE_NAMED_VALUE
State in which value matching field name will
be returned.
|
protected static int |
STATE_NEXT_ENTRY
State in which next entry will be available, returning
either
JsonToken.FIELD_NAME or value
(depending on whether entries are expressed as
Objects or just Arrays); or
matching close marker. |
protected static int |
STATE_RECORD_START
State before logical start of a record, in which next
token to return will be
JsonToken.START_OBJECT
(or if no Schema is provided, JsonToken.START_ARRAY). |
protected static int |
STATE_SKIP_EXTRA_COLUMNS
State in which we have encountered more column values than there should be,
and need to basically skip extra values if callers tries to advance parser
state.
|
protected static int |
STATE_UNNAMED_VALUE
State in which "unnamed" value (entry in an array)
will be returned, if one available; otherwise
end-array is returned.
|
protected static com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability> |
STREAM_READ_CAPABILITIES
CSV is slightly different from defaults, having essentially untyped
scalars except if indicated by schema
|
_currToken, _lastClearedToken, BD_MAX_INT, BD_MAX_LONG, BD_MIN_INT, BD_MIN_LONG, BI_MAX_INT, BI_MAX_LONG, BI_MIN_INT, BI_MIN_LONG, CHAR_NULL, INT_0, INT_9, INT_APOS, INT_ASTERISK, INT_BACKSLASH, INT_COLON, INT_COMMA, INT_CR, INT_e, INT_E, INT_HASH, INT_LBRACKET, INT_LCURLY, INT_LF, INT_MINUS, INT_PERIOD, INT_PLUS, INT_QUOTE, INT_RBRACKET, INT_RCURLY, INT_SLASH, INT_SPACE, INT_TAB, MAX_ERROR_TOKEN_LENGTH, MAX_INT_D, MAX_INT_L, MAX_LONG_D, MIN_INT_D, MIN_INT_L, MIN_LONG_D, NO_BYTES, NO_INTS, NR_BIGDECIMAL, NR_BIGINT, NR_DOUBLE, NR_FLOAT, NR_INT, NR_LONG, NR_UNKNOWN| Constructor and Description |
|---|
CsvParser(CsvIOContext ctxt,
int stdFeatures,
int csvFeatures,
com.fasterxml.jackson.core.ObjectCodec codec,
Reader reader) |
| Modifier and Type | Method and Description |
|---|---|
com.fasterxml.jackson.core.util.ByteArrayBuilder |
_getByteArrayBuilder() |
protected com.fasterxml.jackson.core.JsonToken |
_handleArrayValue() |
protected void |
_handleEOF() |
protected com.fasterxml.jackson.core.JsonToken |
_handleExtraColumn(String value)
Helper method called when an extraneous column value is found.
|
protected com.fasterxml.jackson.core.JsonToken |
_handleMissingColumns()
Helper method called when end of row occurs before finding values for
all schema-specified columns.
|
protected com.fasterxml.jackson.core.JsonToken |
_handleMissingName() |
protected com.fasterxml.jackson.core.JsonToken |
_handleMissingValue() |
protected com.fasterxml.jackson.core.JsonToken |
_handleNamedValue() |
protected com.fasterxml.jackson.core.JsonToken |
_handleNextEntry() |
protected com.fasterxml.jackson.core.JsonToken |
_handleObjectRowEnd()
Helper method called to handle details of state update when end of logical
record occurs.
|
protected com.fasterxml.jackson.core.JsonToken |
_handleRecordStart() |
protected com.fasterxml.jackson.core.JsonToken |
_handleStartDoc()
Method called to handle details of initializing things to return
the very first token.
|
protected com.fasterxml.jackson.core.JsonToken |
_handleUnnamedValue() |
protected void |
_readHeaderLine()
Method called to process the expected header line
|
<T> T |
_reportCsvMappingError(String msg,
Object... args)
Method called when there is a problem related to mapping data
(compared to a low-level generation); if so, should be surfaced
as
|
void |
_reportParsingError(String msg) |
void |
_reportUnexpectedCsvChar(int ch,
String msg) |
protected com.fasterxml.jackson.core.JsonToken |
_skipUntilEndOfLine() |
protected void |
_startArray(CsvSchema.Column column) |
boolean |
canReadObjectId() |
boolean |
canReadTypeId() |
boolean |
canUseSchema(com.fasterxml.jackson.core.FormatSchema schema) |
void |
close() |
com.fasterxml.jackson.core.JsonParser |
configure(CsvParser.Feature f,
boolean state)
Method for enabling or disabling specified CSV feature
(check
CsvParser.Feature for list of features) |
com.fasterxml.jackson.core.JsonParser |
disable(CsvParser.Feature f)
Method for disabling specified CSV feature
(check
CsvParser.Feature for list of features) |
com.fasterxml.jackson.core.JsonParser |
enable(CsvParser.Feature f)
Method for enabling specified CSV feature
(check
CsvParser.Feature for list of features) |
BigInteger |
getBigIntegerValue() |
byte[] |
getBinaryValue(com.fasterxml.jackson.core.Base64Variant variant) |
com.fasterxml.jackson.core.ObjectCodec |
getCodec() |
com.fasterxml.jackson.core.JsonLocation |
getCurrentLocation() |
String |
getCurrentName() |
BigDecimal |
getDecimalValue() |
double |
getDoubleValue() |
Object |
getEmbeddedObject() |
float |
getFloatValue() |
int |
getFormatFeatures() |
Object |
getInputSource() |
int |
getIntValue() |
long |
getLongValue() |
com.fasterxml.jackson.core.JsonParser.NumberType |
getNumberType() |
Number |
getNumberValue() |
Number |
getNumberValueExact() |
com.fasterxml.jackson.core.JsonStreamContext |
getParsingContext() |
com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability> |
getReadCapabilities() |
CsvSchema |
getSchema()
Accessor for getting active schema definition: it may be
"empty" (no column definitions), but will never be null
since it defaults to an empty schema (and default configuration)
|
String |
getText() |
int |
getText(Writer w) |
char[] |
getTextCharacters() |
int |
getTextLength() |
int |
getTextOffset() |
com.fasterxml.jackson.core.JsonLocation |
getTokenLocation() |
boolean |
hasTextCharacters() |
boolean |
isClosed() |
boolean |
isEnabled(CsvParser.Feature f)
Method for checking whether specified CSV
CsvParser.Feature
is enabled. |
boolean |
isExpectedNumberIntToken() |
boolean |
isExpectedStartArrayToken()
We need to override this method to support coercion from basic
String value into array, in cases where schema does not
specify actual type.
|
String |
nextFieldName() |
boolean |
nextFieldName(com.fasterxml.jackson.core.SerializableString str) |
String |
nextTextValue() |
com.fasterxml.jackson.core.JsonToken |
nextToken() |
void |
overrideCurrentName(String name) |
com.fasterxml.jackson.core.JsonParser |
overrideFormatFeatures(int values,
int mask) |
int |
releaseBuffered(Writer out) |
boolean |
requiresCustomCodec() |
void |
setCodec(com.fasterxml.jackson.core.ObjectCodec c) |
void |
setSchema(com.fasterxml.jackson.core.FormatSchema schema) |
com.fasterxml.jackson.core.Version |
version() |
_ascii, _asciiBytes, _constructError, _decodeBase64, _getCharDesc, _hasTextualNull, _longIntegerDesc, _longNumberDesc, _reportError, _reportError, _reportError, _reportInputCoercion, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportInvalidEOFInValue, _reportMissingRootWS, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _wrapError, clearCurrentToken, currentToken, currentTokenId, getCurrentToken, getCurrentTokenId, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, getValueAsString, getValueAsString, hasCurrentToken, hasToken, hasTokenId, isExpectedStartObjectToken, nextValue, reportInvalidNumber, reportOverflowInt, reportOverflowInt, reportOverflowInt, reportOverflowLong, reportOverflowLong, reportOverflowLong, reportUnexpectedNumberChar, skipChildren_codec, _constructError, _reportUnsupportedOperation, canParseAsync, configure, currentName, disable, enable, finishToken, getBinaryValue, getBooleanValue, getByteValue, getCurrentValue, getFeatureMask, getNonBlockingInputFeeder, getObjectId, getShortValue, getTypeId, getValueAsBoolean, getValueAsDouble, isEnabled, isEnabled, isNaN, nextBooleanValue, nextIntValue, nextLongValue, overrideStdFeatures, readBinaryValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, setCurrentValue, setFeatureMask, setRequestPayloadOnError, setRequestPayloadOnError, setRequestPayloadOnErrorprotected static final com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability> STREAM_READ_CAPABILITIES
protected static final int STATE_DOC_START
protected static final int STATE_RECORD_START
JsonToken.START_OBJECT
(or if no Schema is provided, JsonToken.START_ARRAY).protected static final int STATE_NEXT_ENTRY
JsonToken.FIELD_NAME or value
(depending on whether entries are expressed as
Objects or just Arrays); or
matching close marker.protected static final int STATE_NAMED_VALUE
protected static final int STATE_UNNAMED_VALUE
protected static final int STATE_IN_ARRAY
protected static final int STATE_SKIP_EXTRA_COLUMNS
protected static final int STATE_MISSING_NAME
CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS for details.protected static final int STATE_MISSING_VALUE
CsvParser.Feature.INSERT_NULLS_FOR_MISSING_COLUMNS for details.protected static final int STATE_DOC_END
JsonToken.END_ARRAY for wrapping.
This step will loop, returning series of nulls
if nextToken() is called multiple times.protected com.fasterxml.jackson.core.ObjectCodec _objectCodec
protected int _formatFeatures
protected CsvSchema _schema
protected int _columnCount
protected boolean _cfgEmptyStringAsNull
protected com.fasterxml.jackson.core.json.JsonReadContext _parsingContext
protected String _currentName
JsonToken.FIELD_NAME as well as value tokens immediately
following field name.protected String _currentValue
protected int _columnIndex
protected int _state
STATE_
constants.protected byte[] _binaryValue
getBinaryValue(com.fasterxml.jackson.core.Base64Variant) will not need to decode data more
than once.protected int _arrayValueStart
protected String _arrayValue
protected String _arraySeparator
protected String _nullValue
protected final CsvDecoder _reader
protected final TextBuffer _textBuffer
protected com.fasterxml.jackson.core.util.ByteArrayBuilder _byteArrayBuilder
public CsvParser(CsvIOContext ctxt, int stdFeatures, int csvFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader)
public com.fasterxml.jackson.core.Version version()
version in interface com.fasterxml.jackson.core.Versionedversion in class com.fasterxml.jackson.core.JsonParserpublic boolean canUseSchema(com.fasterxml.jackson.core.FormatSchema schema)
canUseSchema in class com.fasterxml.jackson.core.JsonParserpublic boolean requiresCustomCodec()
requiresCustomCodec in class com.fasterxml.jackson.core.JsonParserpublic boolean canReadObjectId()
canReadObjectId in class com.fasterxml.jackson.core.JsonParserpublic boolean canReadTypeId()
canReadTypeId in class com.fasterxml.jackson.core.JsonParserpublic com.fasterxml.jackson.core.util.JacksonFeatureSet<com.fasterxml.jackson.core.StreamReadCapability> getReadCapabilities()
getReadCapabilities in class com.fasterxml.jackson.core.JsonParserpublic com.fasterxml.jackson.core.ObjectCodec getCodec()
getCodec in class com.fasterxml.jackson.core.JsonParserpublic void setCodec(com.fasterxml.jackson.core.ObjectCodec c)
setCodec in class com.fasterxml.jackson.core.JsonParserpublic void setSchema(com.fasterxml.jackson.core.FormatSchema schema)
setSchema in class com.fasterxml.jackson.core.JsonParserpublic int releaseBuffered(Writer out) throws IOException
releaseBuffered in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic boolean isClosed()
isClosed in class com.fasterxml.jackson.core.base.ParserMinimalBasepublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic int getFormatFeatures()
getFormatFeatures in class com.fasterxml.jackson.core.JsonParserpublic com.fasterxml.jackson.core.JsonParser overrideFormatFeatures(int values,
int mask)
overrideFormatFeatures in class com.fasterxml.jackson.core.JsonParserpublic com.fasterxml.jackson.core.JsonParser enable(CsvParser.Feature f)
CsvParser.Feature for list of features)public com.fasterxml.jackson.core.JsonParser disable(CsvParser.Feature f)
CsvParser.Feature for list of features)public com.fasterxml.jackson.core.JsonParser configure(CsvParser.Feature f, boolean state)
CsvParser.Feature for list of features)public boolean isEnabled(CsvParser.Feature f)
CsvParser.Feature
is enabled.public CsvSchema getSchema()
getSchema in class com.fasterxml.jackson.core.JsonParserpublic com.fasterxml.jackson.core.JsonStreamContext getParsingContext()
getParsingContext in class com.fasterxml.jackson.core.base.ParserMinimalBasepublic com.fasterxml.jackson.core.JsonLocation getTokenLocation()
getTokenLocation in class com.fasterxml.jackson.core.JsonParserpublic com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
getCurrentLocation in class com.fasterxml.jackson.core.JsonParserpublic Object getInputSource()
getInputSource in class com.fasterxml.jackson.core.JsonParserpublic boolean isExpectedStartArrayToken()
isExpectedStartArrayToken in class com.fasterxml.jackson.core.base.ParserMinimalBasepublic boolean isExpectedNumberIntToken()
isExpectedNumberIntToken in class com.fasterxml.jackson.core.base.ParserMinimalBasepublic String getCurrentName() throws IOException
getCurrentName in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic void overrideCurrentName(String name)
overrideCurrentName in class com.fasterxml.jackson.core.base.ParserMinimalBasepublic com.fasterxml.jackson.core.JsonToken nextToken()
throws IOException
nextToken in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic boolean nextFieldName(com.fasterxml.jackson.core.SerializableString str)
throws IOException
nextFieldName in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic String nextFieldName() throws IOException
nextFieldName in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic String nextTextValue() throws IOException
nextTextValue in class com.fasterxml.jackson.core.JsonParserIOExceptionprotected void _readHeaderLine()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleStartDoc()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleRecordStart()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleNextEntry()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleNamedValue()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleUnnamedValue()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleArrayValue()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleExtraColumn(String value) throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleMissingColumns()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleMissingName()
throws IOException
IOExceptionprotected com.fasterxml.jackson.core.JsonToken _handleMissingValue()
throws IOException
IOExceptionprotected final com.fasterxml.jackson.core.JsonToken _handleObjectRowEnd()
throws IOException
IOExceptionprotected final com.fasterxml.jackson.core.JsonToken _skipUntilEndOfLine()
throws IOException
IOExceptionpublic boolean hasTextCharacters()
hasTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBasepublic String getText() throws IOException
getText in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic char[] getTextCharacters()
throws IOException
getTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic int getTextLength()
throws IOException
getTextLength in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic int getTextOffset()
throws IOException
getTextOffset in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic int getText(Writer w) throws IOException
getText in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic Object getEmbeddedObject() throws IOException
getEmbeddedObject in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic byte[] getBinaryValue(com.fasterxml.jackson.core.Base64Variant variant)
throws IOException
getBinaryValue in class com.fasterxml.jackson.core.base.ParserMinimalBaseIOExceptionpublic com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()
throws IOException
getNumberType in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic Number getNumberValue() throws IOException
getNumberValue in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic Number getNumberValueExact() throws IOException
getNumberValueExact in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic int getIntValue()
throws IOException
getIntValue in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic long getLongValue()
throws IOException
getLongValue in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic BigInteger getBigIntegerValue() throws IOException
getBigIntegerValue in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic float getFloatValue()
throws IOException
getFloatValue in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic double getDoubleValue()
throws IOException
getDoubleValue in class com.fasterxml.jackson.core.JsonParserIOExceptionpublic BigDecimal getDecimalValue() throws IOException
getDecimalValue in class com.fasterxml.jackson.core.JsonParserIOExceptionprotected void _handleEOF()
throws com.fasterxml.jackson.core.JsonParseException
_handleEOF in class com.fasterxml.jackson.core.base.ParserMinimalBasecom.fasterxml.jackson.core.JsonParseExceptionpublic <T> T _reportCsvMappingError(String msg, Object... args) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic void _reportParsingError(String msg) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic void _reportUnexpectedCsvChar(int ch,
String msg)
throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingExceptionpublic com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder()
protected void _startArray(CsvSchema.Column column)
Copyright © 2020 FasterXML. All rights reserved.