com.fasterxml.jackson.dataformat.csv
Class CsvParser

java.lang.Object
  extended by com.fasterxml.jackson.core.JsonParser
      extended by com.fasterxml.jackson.core.base.ParserMinimalBase
          extended by com.fasterxml.jackson.dataformat.csv.CsvParser
All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned, Closeable

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 CsvReader.


Nested Class Summary
static class CsvParser.Feature
          Enumeration that defines all togglable features for Smile generators.
 
Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonParser
com.fasterxml.jackson.core.JsonParser.NumberType
 
Field Summary
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  int _csvFeatures
           
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  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  CsvReader _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_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_UNNAMED_VALUE
          State in which "unnamed" value (entry in an array) will be returned, if one available; otherwise end-array is returned.
 
Fields inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase
_currToken, _lastClearedToken, INT_APOSTROPHE, INT_ASTERISK, INT_b, INT_BACKSLASH, INT_COLON, INT_COMMA, INT_CR, INT_f, INT_LBRACKET, INT_LCURLY, INT_LF, INT_n, INT_QUOTE, INT_r, INT_RBRACKET, INT_RCURLY, INT_SLASH, INT_SPACE, INT_t, INT_TAB, INT_u
 
Fields inherited from class com.fasterxml.jackson.core.JsonParser
_features
 
Constructor Summary
CsvParser(com.fasterxml.jackson.core.io.IOContext ctxt, com.fasterxml.jackson.core.util.BufferRecycler br, int parserFeatures, int csvFeatures, com.fasterxml.jackson.core.ObjectCodec codec, Reader reader)
           
 
Method Summary
 com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder()
           
protected  void _handleEOF()
           
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 _reportCsvError(String msg)
           
 void _reportUnexpectedCsvChar(int ch, String msg)
           
 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()
           
 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.
 com.fasterxml.jackson.core.JsonToken nextToken()
           
 void overrideCurrentName(String name)
           
 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()
           
 
Methods inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase
_constructError, _decodeBase64, _getCharDesc, _handleUnrecognizedCharacterEscape, _reportBase64EOF, _reportError, _reportInvalidBase64, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _throwUnquotedSpace, _wrapError, clearCurrentToken, getCurrentToken, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsLong, hasCurrentToken, nextValue, skipChildren
 
Methods inherited from class com.fasterxml.jackson.core.JsonParser
_constructError, configure, disable, enable, getBinaryValue, getBooleanValue, getByteValue, getShortValue, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsLong, isEnabled, isExpectedStartArrayToken, nextBooleanValue, nextFieldName, nextIntValue, nextLongValue, nextTextValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_DOC_START

protected static final int STATE_DOC_START
Initial state before anything is read from document.

See Also:
Constant Field Values

STATE_RECORD_START

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).

See Also:
Constant Field Values

STATE_NEXT_ENTRY

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.

See Also:
Constant Field Values

STATE_NAMED_VALUE

protected static final int STATE_NAMED_VALUE
State in which value matching field name will be returned.

See Also:
Constant Field Values

STATE_UNNAMED_VALUE

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.

See Also:
Constant Field Values

STATE_DOC_END

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. This step will loop, returning series of nulls if nextToken() is called multiple times.

See Also:
Constant Field Values

_objectCodec

protected com.fasterxml.jackson.core.ObjectCodec _objectCodec
Codec used for data binding when (if) requested.


_csvFeatures

protected int _csvFeatures

_schema

protected CsvSchema _schema
Definition of columns being read. Initialized to "empty" instance, which has default configuration settings.


_columnCount

protected int _columnCount
Number of columns defined by schema.


_parsingContext

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).


_currentName

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.


_currentValue

protected String _currentValue
String value for the current column, if accessed.


_columnIndex

protected int _columnIndex
Index of the column we are exposing


_state

protected int _state
Current logical state of the parser; one of STATE_ constants.


_binaryValue

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.


_reader

protected final CsvReader _reader
Thing that actually reads the CSV content


_textBuffer

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


_byteArrayBuilder

protected com.fasterxml.jackson.core.util.ByteArrayBuilder _byteArrayBuilder
Constructor Detail

CsvParser

public CsvParser(com.fasterxml.jackson.core.io.IOContext ctxt,
                 com.fasterxml.jackson.core.util.BufferRecycler br,
                 int parserFeatures,
                 int csvFeatures,
                 com.fasterxml.jackson.core.ObjectCodec codec,
                 Reader reader)
Method Detail

version

public com.fasterxml.jackson.core.Version version()
Specified by:
version in interface com.fasterxml.jackson.core.Versioned
Overrides:
version in class com.fasterxml.jackson.core.base.ParserMinimalBase

getCodec

public com.fasterxml.jackson.core.ObjectCodec getCodec()
Specified by:
getCodec in class com.fasterxml.jackson.core.JsonParser

setCodec

public void setCodec(com.fasterxml.jackson.core.ObjectCodec c)
Specified by:
setCodec in class com.fasterxml.jackson.core.JsonParser

canUseSchema

public boolean canUseSchema(com.fasterxml.jackson.core.FormatSchema schema)
Overrides:
canUseSchema in class com.fasterxml.jackson.core.JsonParser

setSchema

public void setSchema(com.fasterxml.jackson.core.FormatSchema schema)
Overrides:
setSchema in class com.fasterxml.jackson.core.JsonParser

releaseBuffered

public int releaseBuffered(Writer out)
                    throws IOException
Overrides:
releaseBuffered in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException

isClosed

public boolean isClosed()
Specified by:
isClosed in class com.fasterxml.jackson.core.base.ParserMinimalBase

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException

enable

public com.fasterxml.jackson.core.JsonParser enable(CsvParser.Feature f)
Method for enabling specified CSV feature (check CsvParser.Feature for list of features)


disable

public com.fasterxml.jackson.core.JsonParser disable(CsvParser.Feature f)
Method for disabling specified CSV feature (check CsvParser.Feature for list of features)


configure

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


isEnabled

public boolean isEnabled(CsvParser.Feature f)
Method for checking whether specified CSV CsvParser.Feature is enabled.


getSchema

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

NOTE: should be part of JsonParser, will be for 2.0.


getParsingContext

public com.fasterxml.jackson.core.JsonStreamContext getParsingContext()
Specified by:
getParsingContext in class com.fasterxml.jackson.core.base.ParserMinimalBase

getTokenLocation

public com.fasterxml.jackson.core.JsonLocation getTokenLocation()
Specified by:
getTokenLocation in class com.fasterxml.jackson.core.JsonParser

getCurrentLocation

public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
Specified by:
getCurrentLocation in class com.fasterxml.jackson.core.JsonParser

getInputSource

public Object getInputSource()
Overrides:
getInputSource in class com.fasterxml.jackson.core.JsonParser

getCurrentName

public String getCurrentName()
                      throws IOException,
                             com.fasterxml.jackson.core.JsonParseException
Specified by:
getCurrentName in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

overrideCurrentName

public void overrideCurrentName(String name)
Specified by:
overrideCurrentName in class com.fasterxml.jackson.core.base.ParserMinimalBase

nextToken

public com.fasterxml.jackson.core.JsonToken nextToken()
                                               throws IOException,
                                                      com.fasterxml.jackson.core.JsonParseException
Specified by:
nextToken in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleStartDoc

protected com.fasterxml.jackson.core.JsonToken _handleStartDoc()
                                                        throws IOException,
                                                               com.fasterxml.jackson.core.JsonParseException
Method called to handle details of initializing things to return the very first token.

Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleRecordStart

protected com.fasterxml.jackson.core.JsonToken _handleRecordStart()
                                                           throws IOException,
                                                                  com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleNextEntry

protected com.fasterxml.jackson.core.JsonToken _handleNextEntry()
                                                         throws IOException,
                                                                com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleNamedValue

protected com.fasterxml.jackson.core.JsonToken _handleNamedValue()
                                                          throws IOException,
                                                                 com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleUnnamedValue

protected com.fasterxml.jackson.core.JsonToken _handleUnnamedValue()
                                                            throws IOException,
                                                                   com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_readHeaderLine

protected void _readHeaderLine()
                        throws IOException,
                               com.fasterxml.jackson.core.JsonParseException
Method called to process the expected header line

Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

hasTextCharacters

public boolean hasTextCharacters()
Specified by:
hasTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBase

getText

public String getText()
               throws IOException,
                      com.fasterxml.jackson.core.JsonParseException
Specified by:
getText in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getTextCharacters

public char[] getTextCharacters()
                         throws IOException,
                                com.fasterxml.jackson.core.JsonParseException
Specified by:
getTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getTextLength

public int getTextLength()
                  throws IOException,
                         com.fasterxml.jackson.core.JsonParseException
Specified by:
getTextLength in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getTextOffset

public int getTextOffset()
                  throws IOException,
                         com.fasterxml.jackson.core.JsonParseException
Specified by:
getTextOffset in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getEmbeddedObject

public Object getEmbeddedObject()
                         throws IOException,
                                com.fasterxml.jackson.core.JsonParseException
Specified by:
getEmbeddedObject in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getBinaryValue

public byte[] getBinaryValue(com.fasterxml.jackson.core.Base64Variant variant)
                      throws IOException,
                             com.fasterxml.jackson.core.JsonParseException
Specified by:
getBinaryValue in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getNumberType

public com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()
                                                               throws IOException,
                                                                      com.fasterxml.jackson.core.JsonParseException
Specified by:
getNumberType in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getNumberValue

public Number getNumberValue()
                      throws IOException,
                             com.fasterxml.jackson.core.JsonParseException
Specified by:
getNumberValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getIntValue

public int getIntValue()
                throws IOException,
                       com.fasterxml.jackson.core.JsonParseException
Specified by:
getIntValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getLongValue

public long getLongValue()
                  throws IOException,
                         com.fasterxml.jackson.core.JsonParseException
Specified by:
getLongValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getBigIntegerValue

public BigInteger getBigIntegerValue()
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonParseException
Specified by:
getBigIntegerValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getFloatValue

public float getFloatValue()
                    throws IOException,
                           com.fasterxml.jackson.core.JsonParseException
Specified by:
getFloatValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getDoubleValue

public double getDoubleValue()
                      throws IOException,
                             com.fasterxml.jackson.core.JsonParseException
Specified by:
getDoubleValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getDecimalValue

public BigDecimal getDecimalValue()
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonParseException
Specified by:
getDecimalValue in class com.fasterxml.jackson.core.JsonParser
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleEOF

protected void _handleEOF()
                   throws com.fasterxml.jackson.core.JsonParseException
Specified by:
_handleEOF in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
com.fasterxml.jackson.core.JsonParseException

_reportCsvError

public void _reportCsvError(String msg)
                     throws com.fasterxml.jackson.core.JsonParseException
Throws:
com.fasterxml.jackson.core.JsonParseException

_reportUnexpectedCsvChar

public void _reportUnexpectedCsvChar(int ch,
                                     String msg)
                              throws com.fasterxml.jackson.core.JsonParseException
Throws:
com.fasterxml.jackson.core.JsonParseException

_getByteArrayBuilder

public com.fasterxml.jackson.core.util.ByteArrayBuilder _getByteArrayBuilder()


Copyright © 2012 fasterxml.com. All Rights Reserved.