Top Description Fields Constructors Methods
tools.jackson.dataformat.csv

public Class CsvParser

extends ParserMinimalBase
Class Inheritance
Imports
java.io.IOException, .Reader, .Writer, java.math.BigDecimal, .BigInteger, java.util.LinkedHashSet, .Set, tools.jackson.core.*, tools.jackson.core.base.ParserMinimalBase, tools.jackson.core.exc.StreamReadException, tools.jackson.core.io.IOContext, tools.jackson.core.json.DupDetector, tools.jackson.core.util.ByteArrayBuilder, .JacksonFeatureSet, .SimpleStreamReadContext, .TextBuffer, tools.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.

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#PROPERTY_NAME as well as value tokens immediately following property name.

protected String
_currentValue

String value for the current column, if accessed.

protected int
protected String
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 SimpleStreamReadContext
_streamReadContext

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

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 CsvReadFeature#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 CsvReadFeature#INSERT_NULLS_FOR_MISSING_COLUMNS for details.

protected static final int
STATE_NAMED_VALUE

State in which value matching property name will be returned.

protected static final int
STATE_NEXT_ENTRY

State in which next entry will be available, returning either JsonToken#PROPERTY_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 tools.jackson.core.base.ParserMinimalBase:
_closed_currToken_ioContext_lastClearedToken_objectReadContext_streamReadConstraints_streamReadFeatures_tokenCount_trackMaxTokenCountBD_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_RSINT_SLASHINT_SPACEINT_TABMAX_BYTE_IMAX_INT_DMAX_INT_LMAX_LONG_DMAX_SHORT_IMIN_BYTE_IMIN_INT_DMIN_INT_LMIN_LONG_DMIN_SHORT_INO_BYTESNO_INTSNR_BIGDECIMALNR_BIGINTNR_DOUBLENR_FLOATNR_INTNR_LONGNR_UNKNOWNSTREAM_READ_FEATURE_DEFAULTS

Constructor Summary

AccessConstructor and Description
public
CsvParser(ObjectReadContext readCtxt, IOContext ioCtxt, int stdFeatures, int csvFeatures, CsvSchema schema, Reader reader)

Method Summary

Modifier and TypeMethod and Description
protected void
_closeInput()

Implements abstract tools.jackson.core.base.ParserMinimalBase._closeInput.

Abstract method for sub-classes to implement; to be called by close() implementation here.

public ByteArrayBuilder
protected JsonToken
protected void
_handleEOF()

Implements abstract tools.jackson.core.base.ParserMinimalBase._handleEOF.

Method sub-classes need to implement to check whether end-of-content is allowed at the current decoding position: formats often want to verify the all start/end token pairs match, for example.

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

protected void
_releaseBuffers()

Implements abstract tools.jackson.core.base.ParserMinimalBase._releaseBuffers.

Method called to release internal buffers owned by the base reader.

public <T> T
_reportCsvReadError(String msg, Object... args)

Method called when there is a problem related to mapping CSV columns to property names, i.e. is CSV-specific aspect

public <T> T
protected <T> T
public <T> T
protected void
protected final JsonToken
protected void
protected void
public JacksonException
public void
assignCurrentValue(Object v)

Implements abstract tools.jackson.core.JsonParser.assignCurrentValue.

Helper method, usually equivalent to: getParsingContext().assignCurrentValue(v);

public boolean
canReadObjectId()

Overrides tools.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 tools.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 JsonParser
configure(CsvReadFeature f, boolean state)

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

public TokenStreamLocation
currentLocation()

Implements abstract tools.jackson.core.JsonParser.currentLocation.

Method that returns location of the last processed character; usually for error reporting purposes.

public String
currentName()

Implements abstract tools.jackson.core.JsonParser.currentName.

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

public TokenStreamLocation
currentTokenLocation()

Implements abstract tools.jackson.core.JsonParser.currentTokenLocation.

Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.

public Object
currentValue()

Implements abstract tools.jackson.core.JsonParser.currentValue.

Helper method, usually equivalent to: getParsingContext().currentValue();

Note that "current value" is NOT populated (or used) by Streaming parser; it is only used by higher-level data-binding functionality.

public JsonParser
disable(CsvReadFeature f)

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

public JsonParser
enable(CsvReadFeature f)

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

public BigInteger
getBigIntegerValue()

Implements abstract tools.jackson.core.JsonParser.getBigIntegerValue.

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

public byte[]
getBinaryValue(Base64Variant variant)

Implements abstract tools.jackson.core.JsonParser.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 BigDecimal
getDecimalValue()

Implements abstract tools.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 tools.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 tools.jackson.core.base.ParserMinimalBase.getEmbeddedObject.

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

public float
getFloatValue()

Implements abstract tools.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
getIntValue()

Implements abstract tools.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 tools.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 tools.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 Number
getNumberValue()

Implements abstract tools.jackson.core.JsonParser.getNumberValue.

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

public Number
getNumberValueExact()

Overrides tools.jackson.core.base.ParserMinimalBase.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 CsvSchema
getSchema()

Overrides tools.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
getString()

Implements abstract tools.jackson.core.JsonParser.getString.

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
getString(Writer w)

Overrides tools.jackson.core.base.ParserMinimalBase.getString.

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

public char[]
getStringCharacters()

Implements abstract tools.jackson.core.JsonParser.getStringCharacters.

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

public int
getStringLength()

Implements abstract tools.jackson.core.JsonParser.getStringLength.

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

public int
getStringOffset()

Implements abstract tools.jackson.core.JsonParser.getStringOffset.

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

public boolean
hasStringCharacters()

Implements abstract tools.jackson.core.JsonParser.hasStringCharacters.

Method that can be used to determine whether calling of getStringCharacters would be the most efficient way to access String value for the event parser currently points to (compared to getString()).

public boolean
isEnabled(CsvReadFeature f)

Method for checking whether specified CSV CsvReadFeature is enabled.

public boolean
public boolean
isExpectedStartArrayToken()

Overrides tools.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
isNaN()

Implements abstract tools.jackson.core.JsonParser.isNaN.

Accessor for checking whether current token is a special "not-a-number" (NaN) token (including both "NaN" AND positive/negative infinity!).

public boolean
nextName(SerializableString str)

Overrides tools.jackson.core.base.ParserMinimalBase.nextName.

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

public String
nextName()

Overrides tools.jackson.core.base.ParserMinimalBase.nextName.

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

public String
nextStringValue()

Overrides tools.jackson.core.JsonParser.nextStringValue.

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 tools.jackson.core.JsonParser.nextToken.

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

public int
releaseBuffered(Writer out)

Overrides tools.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 JacksonFeatureSet<StreamReadCapability>
streamReadCapabilities()

Overrides tools.jackson.core.base.ParserMinimalBase.streamReadCapabilities.

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

public TokenStreamContext
streamReadContext()

Implements abstract tools.jackson.core.JsonParser.streamReadContext.

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 Object
streamReadInputSource()

Implements abstract tools.jackson.core.JsonParser.streamReadInputSource.

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 Version
version()

Implements abstract tools.jackson.core.JsonParser.version.

Implements tools.jackson.core.Versioned.version.

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

Inherited from tools.jackson.core.base.ParserMinimalBase:
_constructInputCoercion_constructNotNumericType_currentLocationMinusOne_decodeBase64_getCharDesc_hasTextualNull_longIntegerDesc_longNumberDesc_nullSafeUpdateToken_reportBadInputStream_reportBadReader_reportError_reportError_reportError_reportInvalidEOF_reportInvalidEOF_reportInvalidEOFInValue_reportInvalidNumber_reportInvalidSpace_reportMissingRootWS_reportOverflowByte_reportOverflowInt_reportOverflowInt_reportOverflowInt_reportOverflowLong_reportOverflowLong_reportOverflowLong_reportOverflowShort_reportUnexpectedChar_reportUnexpectedNumberChar_throwInternal_updateToken_updateTokenToNA_updateTokenToNullclearCurrentTokenclosecurrentNameMatchcurrentTokencurrentTokenCountcurrentTokenIdfinishTokengetBooleanValuegetByteValuegetLastClearedTokengetNumberTypeFPgetNumberValueDeferredgetShortValuegetValueAsBooleangetValueAsDoublegetValueAsIntgetValueAsIntgetValueAsLonggetValueAsLonggetValueAsStringgetValueAsStringhasCurrentTokenhasTokenhasTokenIdisClosedisEnabledisExpectedStartObjectTokennextNameMatchnextValueobjectReadContextreadValueAsreadValueAsreadValueAsreadValueAsTreeskipChildrenstreamReadConstraintsstreamReadFeatures