Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.dataformat.csv

public Class CsvParser

extends ParserMinimalBase
Class Inheritance
Imports
java.io.*, java.math.BigDecimal, .BigInteger, java.util.LinkedHashSet, .Objects, .Set, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.base.ParserMinimalBase, com.fasterxml.jackson.core.exc.StreamConstraintsException, com.fasterxml.jackson.core.io.IOContext, com.fasterxml.jackson.core.json.DupDetector, .JsonReadContext, com.fasterxml.jackson.core.util.ByteArrayBuilder, .JacksonFeatureSet, .TextBuffer, com.fasterxml.jackson.dataformat.csv.impl.CsvDecoder

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
CsvParser.Feature

Enumeration that defines all togglable features for CSV parsers

Field Summary

Modifier and TypeField and Description
protected String
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 will not need to decode data more than once.

protected ByteArrayBuilder
protected boolean
protected boolean
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
protected final IOContext
protected String
protected ObjectCodec
_objectCodec

Codec used for data binding when (if) requested.

protected JsonReadContext
_parsingContext

Information about parser context, context in which the next token is to be parsed (root, array, object).

protected final 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 final TextBuffer
_textBuffer

Buffer that contains contents of all values after processing of doubled-quotes, escaped characters.

private static final CsvSchema
private static final int
protected static final 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 final int
STATE_DOC_START

Initial state before anything is read from document.

protected static final 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 final 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 Feature#INSERT_NULLS_FOR_MISSING_COLUMNS for details.

protected static final int
STATE_MISSING_VALUE

State in which we should expose `null` value token as a value for "missing" column; see Feature#INSERT_NULLS_FOR_MISSING_COLUMNS for details.

protected static final int
STATE_NAMED_VALUE

State in which value matching field name will be returned.

protected static final 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 final 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 final 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 final 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 final JacksonFeatureSet<StreamReadCapability>
STREAM_READ_CAPABILITIES

CSV is slightly different from defaults, having essentially untyped scalars except if indicated by schema

Inherited from com.fasterxml.jackson.core.base.ParserMinimalBase:
_currToken_lastClearedTokenBD_MAX_INTBD_MAX_LONGBD_MIN_INTBD_MIN_LONGBI_MAX_INTBI_MAX_LONGBI_MIN_INTBI_MIN_LONGCHAR_NULLINT_0INT_9INT_APOSINT_ASTERISKINT_BACKSLASHINT_COLONINT_COMMAINT_CRINT_eINT_EINT_HASHINT_LBRACKETINT_LCURLYINT_LFINT_MINUSINT_PERIODINT_PLUSINT_QUOTEINT_RBRACKETINT_RCURLYINT_SLASHINT_SPACEINT_TABMAX_ERROR_TOKEN_LENGTHMAX_INT_DMAX_INT_LMAX_LONG_DMIN_INT_DMIN_INT_LMIN_LONG_DNO_BYTESNO_INTSNR_BIGDECIMALNR_BIGINTNR_DOUBLENR_FLOATNR_INTNR_LONGNR_UNKNOWN

Constructor Summary

AccessConstructor and Description
public
CsvParser(IOContext ctxt, int stdFeatures, int csvFeatures, ObjectCodec codec, Reader reader)

Method Summary

Modifier and TypeMethod and Description
public ByteArrayBuilder
protected JsonToken
protected void
_handleEOF()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase._handleEOF.

Method sub-classes need to implement for verifying that end-of-content is acceptable at current input position.

protected JsonToken
_handleExtraColumn(String value)

Helper method called when an extraneous column value is found.

protected JsonToken
_handleMissingColumns()

Helper method called when end of row occurs before finding values for all schema-specified columns.

protected JsonToken
protected JsonToken
protected JsonToken
protected JsonToken
protected final JsonToken
_handleObjectRowEnd()

Helper method called to handle details of state update when end of logical record occurs.

protected JsonToken
protected JsonToken
_handleStartDoc()

Method called to handle details of initializing things to return the very first token.

protected JsonToken
protected boolean
_isNullValue(String value)

Helper method called to check whether specified String value should be considered "null" value, if so configured.

protected void
_readHeaderLine()

Method called to process the expected header line

public <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

public void
public void
protected final JsonToken
protected void
public boolean
canReadObjectId()

Overrides com.fasterxml.jackson.core.JsonParser.canReadObjectId.

Introspection method that may be called to see if the underlying data format supports some kind of Object Ids natively (many do not; for example, JSON doesn't).

public boolean
canReadTypeId()

Overrides com.fasterxml.jackson.core.JsonParser.canReadTypeId.

Introspection method that may be called to see if the underlying data format supports some kind of Type Ids natively (many do not; for example, JSON doesn't).

public boolean
canUseSchema(FormatSchema
Schema to check
schema
)

Overrides com.fasterxml.jackson.core.JsonParser.canUseSchema.

Method that can be used to verify that given schema can be used with this parser (using setSchema).

public void
close()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.close.

Implements java.io.Closeable.close.

Closes the parser so that no further iteration or data access can be made; will also close the underlying input source if parser either owns the input source, or feature Feature#AUTO_CLOSE_SOURCE is enabled.

public JsonParser
configure(CsvParser.Feature f, boolean state)

Method for enabling or disabling specified CSV feature (check Feature for list of features)

public JsonLocation
currentLocation()

Overrides com.fasterxml.jackson.core.JsonParser.currentLocation.

Method that returns location of the last processed input unit (character or byte) from the input; usually for error reporting purposes.

public String
currentName()

Overrides com.fasterxml.jackson.core.JsonParser.currentName.

Method that can be called to get the name associated with the current token: for JsonToken#FIELD_NAMEs it will be the same as what getText returns; for field values it will be preceding field name; and for others (array values, root-level values) null.

public JsonLocation
currentTokenLocation()

Overrides com.fasterxml.jackson.core.JsonParser.currentTokenLocation.

Method that return the starting location of the current (most recently returned) token; that is, the position of the first input unit (character or byte) from input that starts the current token.

public JsonParser
disable(CsvParser.Feature f)

Method for disabling specified CSV feature (check Feature for list of features)

public JsonParser
enable(CsvParser.Feature f)

Method for enabling specified CSV feature (check Feature for list of features)

public BigInteger
getBigIntegerValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getBigIntegerValue.

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_INT and it can not be used as a Java long primitive type due to its magnitude.

public byte[]
getBinaryValue(Base64Variant
Expected variant of base64 encoded content (see Base64Variants for definitions of "standard" variants).
variant
)

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.getBinaryValue.

Method that can be used to read (and consume -- results may not be accessible using other methods after the call) base64-encoded binary data included in the current textual JSON value.

public ObjectCodec
getCodec()

Implements abstract com.fasterxml.jackson.core.JsonParser.getCodec.

Accessor for ObjectCodec associated with this parser, if any.

public JsonLocation
getCurrentLocation()

Implements abstract com.fasterxml.jackson.core.JsonParser.getCurrentLocation.

Deprecated

Deprecated alias for currentLocation() (removed from Jackson 3.0).

public String
public BigDecimal
getDecimalValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getDecimalValue.

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_FLOAT or JsonToken#VALUE_NUMBER_INT.

public double
getDoubleValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getDoubleValue.

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_FLOAT and it can be expressed as a Java double primitive type.

public Object
getEmbeddedObject()

Overrides com.fasterxml.jackson.core.JsonParser.getEmbeddedObject.

Accessor that can be called if (and only if) the current token is JsonToken#VALUE_EMBEDDED_OBJECT.

public float
getFloatValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getFloatValue.

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_FLOAT and it can be expressed as a Java float primitive type.

public int
getFormatFeatures()

Overrides com.fasterxml.jackson.core.JsonParser.getFormatFeatures.

Bulk access method for getting state of all FormatFeatures, format-specific on/off configuration settings.

public Object
getInputSource()

Overrides com.fasterxml.jackson.core.JsonParser.getInputSource.

Method that can be used to get access to object that is used to access input being parsed; this is usually either InputStream or Reader, depending on what parser was constructed with.

public int
getIntValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getIntValue.

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_INT and it can be expressed as a value of Java int primitive type.

public long
getLongValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getLongValue.

Numeric accessor that can be called when the current token is of type JsonToken#VALUE_NUMBER_INT and it can be expressed as a Java long primitive type.

public JsonParser.NumberType
getNumberType()

Implements abstract com.fasterxml.jackson.core.JsonParser.getNumberType.

If current token is of type JsonToken#VALUE_NUMBER_INT or JsonToken#VALUE_NUMBER_FLOAT, returns one of NumberType constants; otherwise returns null.

public JsonParser.NumberTypeFP
getNumberTypeFP()

Overrides com.fasterxml.jackson.core.JsonParser.getNumberTypeFP.

If current token is of type JsonToken#VALUE_NUMBER_FLOAT, returns one of NumberTypeFP constants; otherwise returns NumberTypeFP#UNKNOWN.

public Number
getNumberValue()

Implements abstract com.fasterxml.jackson.core.JsonParser.getNumberValue.

Generic number value accessor method that will work for all kinds of numeric values.

public Number
getNumberValueExact()

Overrides com.fasterxml.jackson.core.JsonParser.getNumberValueExact.

Method similar to getNumberValue with the difference that for floating-point numbers value returned may be BigDecimal if the underlying format does not store floating-point numbers using native representation: for example, textual formats represent numbers as Strings (which are 10-based), and conversion to java.lang.Double is potentially lossy operation.

public JsonStreamContext
getParsingContext()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.getParsingContext.

Method that can be used to access current parsing context reader is in. There are 3 different types: root, array and object contexts, with slightly different available information.

public JacksonFeatureSet<StreamReadCapability>
getReadCapabilities()

Overrides com.fasterxml.jackson.core.JsonParser.getReadCapabilities.

Accessor for getting metadata on capabilities of this parser, based on underlying data format being read (directly or indirectly).

public CsvSchema
getSchema()

Overrides com.fasterxml.jackson.core.JsonParser.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)

public String
getText()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.getText.

Method for accessing textual representation of the current token; if no current token (before first call to nextToken, or after encountering end-of-input), returns null.

public int
getText(Writer
Writer to write textual content to
w
)

Overrides com.fasterxml.jackson.core.JsonParser.getText.

Method to read the textual representation of the current token in chunks and pass it to the given Writer.

public char[]
getTextCharacters()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.getTextCharacters.

Method similar to getText, but that will return underlying (unmodifiable) character array that contains textual value, instead of constructing a String object to contain this information.

public int
getTextLength()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.getTextLength.

Accessor used with getTextCharacters, to know length of String stored in returned buffer.

public int
getTextOffset()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.getTextOffset.

Accessor used with getTextCharacters, to know offset of the first text content character within buffer.

public JsonLocation
getTokenLocation()

Implements abstract com.fasterxml.jackson.core.JsonParser.getTokenLocation.

Deprecated

Deprecated alias for currentTokenLocation() (removed from Jackson 3.0).

public boolean
hasTextCharacters()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.hasTextCharacters.

Method that can be used to determine whether calling of getTextCharacters would be the most efficient way to access textual content for the event parser currently points to.

public boolean
isClosed()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.isClosed.

Method that can be called to determine whether this parser is closed or not.

public boolean
isEnabled(CsvParser.Feature f)

Method for checking whether specified CSV Feature is enabled.

public boolean

Returns:

Whether the token can be read as JsonToken.VALUE_NUMBER_INT (with possible coercion)
isExpectedNumberIntToken
()

Overrides com.fasterxml.jackson.core.base.ParserMinimalBase.isExpectedNumberIntToken.

Similar to isExpectedStartArrayToken(), but checks whether stream currently points to JsonToken#VALUE_NUMBER_INT.

public boolean
isExpectedStartArrayToken()

Overrides com.fasterxml.jackson.core.base.ParserMinimalBase.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.

public boolean
nextFieldName(SerializableString
Property name to compare next token to (if next token is JsonToken.FIELD_NAME)
str
)

Overrides com.fasterxml.jackson.core.JsonParser.nextFieldName.

Method that fetches next token (as if calling nextToken) and verifies whether it is JsonToken#FIELD_NAME with specified name and returns result of that comparison.

public String
nextFieldName()

Overrides com.fasterxml.jackson.core.JsonParser.nextFieldName.

Method that fetches next token (as if calling nextToken) and verifies whether it is JsonToken#FIELD_NAME; if it is, returns same as currentName(), otherwise null.

public String
nextTextValue()

Overrides com.fasterxml.jackson.core.JsonParser.nextTextValue.

Method that fetches next token (as if calling nextToken) and if it is JsonToken#VALUE_STRING returns contained String value; otherwise returns null.

public JsonToken
nextToken()

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.nextToken.

Main iteration method, which will advance stream enough to determine type of the next token, if any.

public void
overrideCurrentName(String
Name to use as the current name; may be null.
name
)

Implements abstract com.fasterxml.jackson.core.base.ParserMinimalBase.overrideCurrentName.

Method that can be used to change what is considered to be the current (field) name.

public JsonParser
overrideFormatFeatures(int
Bit mask of set/clear state for features to change
values
,
int
Bit mask of features to change
mask
)

Overrides com.fasterxml.jackson.core.JsonParser.overrideFormatFeatures.

Bulk set method for (re)setting states of FormatFeatures, by specifying values (set / clear) along with a mask, to determine which features to change, if any.

public int
releaseBuffered(Writer
Writer to which buffered but unprocessed content is written to
out
)

Overrides com.fasterxml.jackson.core.JsonParser.releaseBuffered.

Method that can be called to push back any content that has been read but not consumed by the parser.

public boolean
requiresCustomCodec()

Overrides com.fasterxml.jackson.core.JsonParser.requiresCustomCodec.

Method that can be called to determine if a custom ObjectCodec is needed for binding data parsed using JsonParser constructed by this factory (which typically also implies the same for serialization with JsonGenerator).

public void
setCodec(ObjectCodec
Codec to assign, if any; null if none
c
)

Implements abstract com.fasterxml.jackson.core.JsonParser.setCodec.

Setter that allows defining ObjectCodec associated with this parser, if any.

public void
setSchema(final FormatSchema
Schema to use
schema
)

Overrides com.fasterxml.jackson.core.JsonParser.setSchema.

Method to call to make this parser use specified schema.

public Version
version()

Implements abstract com.fasterxml.jackson.core.JsonParser.version.

Implements com.fasterxml.jackson.core.Versioned.version.

Accessor for getting version of the core package, given a parser instance.

Inherited from com.fasterxml.jackson.core.base.ParserMinimalBase:
_ascii_asciiBytes_constructError_decodeBase64_getCharDesc_hasTextualNull_longIntegerDesc_longNumberDesc_reportError_reportError_reportError_reportInputCoercion_reportInvalidEOF_reportInvalidEOF_reportInvalidEOF_reportInvalidEOFInValue_reportInvalidEOFInValue_reportMissingRootWS_reportUnexpectedChar_reportUnexpectedNumberChar_throwInternal_throwInvalidSpace_wrapErrorclearCurrentTokencurrentTokencurrentTokenIdgetCurrentTokengetCurrentTokenIdgetLastClearedTokengetValueAsBooleangetValueAsDoublegetValueAsIntgetValueAsIntgetValueAsLonggetValueAsLonggetValueAsStringgetValueAsStringhasCurrentTokenhasTokenhasTokenIdisExpectedStartObjectTokennextValuereportInvalidNumberreportOverflowIntreportOverflowIntreportOverflowIntreportOverflowLongreportOverflowLongreportOverflowLongreportUnexpectedNumberCharskipChildren