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 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_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.
|
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 |
_handleNamedValue() |
protected com.fasterxml.jackson.core.JsonToken |
_handleNextEntry() |
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
|
void |
_reportMappingError(String msg)
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 |
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() |
com.fasterxml.jackson.core.JsonStreamContext |
getParsingContext() |
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() |
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 |
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) |
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, _handleUnrecognizedCharacterEscape, _hasTextualNull, _reportError, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportMissingRootWS, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _throwUnquotedSpace, _wrapError, clearCurrentToken, getCurrentToken, getCurrentTokenId, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, getValueAsString, getValueAsString, hasCurrentToken, hasToken, hasTokenId, isExpectedStartObjectToken, nextValue, skipChildren
_codec, _constructError, _reportUnsupportedOperation, canReadObjectId, canReadTypeId, configure, disable, enable, getBinaryValue, getBooleanValue, getByteValue, getCurrentValue, getFeatureMask, getObjectId, getShortValue, getTypeId, getValueAsBoolean, getValueAsDouble, isEnabled, nextBooleanValue, nextIntValue, nextLongValue, overrideStdFeatures, readBinaryValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, requiresCustomCodec, setCurrentValue, setFeatureMask
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_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 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.Versioned
version
in class com.fasterxml.jackson.core.JsonParser
public com.fasterxml.jackson.core.ObjectCodec getCodec()
getCodec
in class com.fasterxml.jackson.core.JsonParser
public void setCodec(com.fasterxml.jackson.core.ObjectCodec c)
setCodec
in class com.fasterxml.jackson.core.JsonParser
public boolean canUseSchema(com.fasterxml.jackson.core.FormatSchema schema)
canUseSchema
in class com.fasterxml.jackson.core.JsonParser
public void setSchema(com.fasterxml.jackson.core.FormatSchema schema)
setSchema
in class com.fasterxml.jackson.core.JsonParser
public int releaseBuffered(Writer out) throws IOException
releaseBuffered
in class com.fasterxml.jackson.core.JsonParser
IOException
public boolean isClosed()
isClosed
in class com.fasterxml.jackson.core.base.ParserMinimalBase
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public int getFormatFeatures()
getFormatFeatures
in class com.fasterxml.jackson.core.JsonParser
public com.fasterxml.jackson.core.JsonParser overrideFormatFeatures(int values, int mask)
overrideFormatFeatures
in class com.fasterxml.jackson.core.JsonParser
public 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.JsonParser
public com.fasterxml.jackson.core.JsonStreamContext getParsingContext()
getParsingContext
in class com.fasterxml.jackson.core.base.ParserMinimalBase
public com.fasterxml.jackson.core.JsonLocation getTokenLocation()
getTokenLocation
in class com.fasterxml.jackson.core.JsonParser
public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
getCurrentLocation
in class com.fasterxml.jackson.core.JsonParser
public Object getInputSource()
getInputSource
in class com.fasterxml.jackson.core.JsonParser
public boolean isExpectedStartArrayToken()
isExpectedStartArrayToken
in class com.fasterxml.jackson.core.base.ParserMinimalBase
public String getCurrentName() throws IOException
getCurrentName
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public void overrideCurrentName(String name)
overrideCurrentName
in class com.fasterxml.jackson.core.base.ParserMinimalBase
public com.fasterxml.jackson.core.JsonToken nextToken() throws IOException
nextToken
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public boolean nextFieldName(com.fasterxml.jackson.core.SerializableString str) throws IOException
nextFieldName
in class com.fasterxml.jackson.core.JsonParser
IOException
public String nextFieldName() throws IOException
nextFieldName
in class com.fasterxml.jackson.core.JsonParser
IOException
public String nextTextValue() throws IOException
nextTextValue
in class com.fasterxml.jackson.core.JsonParser
IOException
protected com.fasterxml.jackson.core.JsonToken _handleStartDoc() throws IOException
IOException
protected com.fasterxml.jackson.core.JsonToken _handleRecordStart() throws IOException
IOException
protected com.fasterxml.jackson.core.JsonToken _handleNextEntry() throws IOException
IOException
protected com.fasterxml.jackson.core.JsonToken _handleExtraColumn(String value) throws IOException
IOException
protected com.fasterxml.jackson.core.JsonToken _handleNamedValue() throws IOException
IOException
protected com.fasterxml.jackson.core.JsonToken _handleUnnamedValue() throws IOException
IOException
protected com.fasterxml.jackson.core.JsonToken _handleArrayValue() throws IOException
IOException
protected void _readHeaderLine() throws IOException
IOException
protected final com.fasterxml.jackson.core.JsonToken _skipUntilEndOfLine() throws IOException
IOException
public boolean hasTextCharacters()
hasTextCharacters
in class com.fasterxml.jackson.core.base.ParserMinimalBase
public String getText() throws IOException
getText
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public char[] getTextCharacters() throws IOException
getTextCharacters
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public int getTextLength() throws IOException
getTextLength
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public int getTextOffset() throws IOException
getTextOffset
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public Object getEmbeddedObject() throws IOException
getEmbeddedObject
in class com.fasterxml.jackson.core.JsonParser
IOException
public byte[] getBinaryValue(com.fasterxml.jackson.core.Base64Variant variant) throws IOException
getBinaryValue
in class com.fasterxml.jackson.core.base.ParserMinimalBase
IOException
public com.fasterxml.jackson.core.JsonParser.NumberType getNumberType() throws IOException
getNumberType
in class com.fasterxml.jackson.core.JsonParser
IOException
public Number getNumberValue() throws IOException
getNumberValue
in class com.fasterxml.jackson.core.JsonParser
IOException
public int getIntValue() throws IOException
getIntValue
in class com.fasterxml.jackson.core.JsonParser
IOException
public long getLongValue() throws IOException
getLongValue
in class com.fasterxml.jackson.core.JsonParser
IOException
public BigInteger getBigIntegerValue() throws IOException
getBigIntegerValue
in class com.fasterxml.jackson.core.JsonParser
IOException
public float getFloatValue() throws IOException
getFloatValue
in class com.fasterxml.jackson.core.JsonParser
IOException
public double getDoubleValue() throws IOException
getDoubleValue
in class com.fasterxml.jackson.core.JsonParser
IOException
public BigDecimal getDecimalValue() throws IOException
getDecimalValue
in class com.fasterxml.jackson.core.JsonParser
IOException
protected void _handleEOF() throws com.fasterxml.jackson.core.JsonParseException
_handleEOF
in class com.fasterxml.jackson.core.base.ParserMinimalBase
com.fasterxml.jackson.core.JsonParseException
public void _reportMappingError(String msg) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
public void _reportParsingError(String msg) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
public void _reportUnexpectedCsvChar(int ch, String msg) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
public com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder()
protected void _startArray(CsvSchema.Column column)
Copyright © 2016 FasterXML. All rights reserved.