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

public Class CsvDecoder

extends Object
Class Inheritance
Imports
java.io.*, java.math.BigDecimal, .BigInteger, com.fasterxml.jackson.core.*, .JsonParser.NumberType, com.fasterxml.jackson.core.io.NumberInput, .IOContext, com.fasterxml.jackson.core.json.JsonReadContext, com.fasterxml.jackson.core.util.TextBuffer, com.fasterxml.jackson.dataformat.csv.CsvParser, .CsvSchema

Low-level helper class that handles actual reading of CSV, purely based on indexes given without worrying about reordering etc.

Field Summary

Modifier and TypeField and Description
protected boolean
protected boolean
protected boolean
_bufferRecyclable

Flag that indicates whether the input buffer is recycable (and needs to be returned to recycler once we are done) or not.

protected boolean
_closed

Flag that indicates whether parser is closed or not.

protected long
_currInputProcessed

Number of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer).

protected boolean
_currInputQuoted

Flag that indicates whether the current token has been quoted or not.

protected int
_currInputRow

Current row location of current point in input buffer, starting from 1, if available.

protected int
_currInputRowStart

Current index of the first character of the current row in input buffer.

protected int
protected char[]
_inputBuffer

Current buffer from which data is read; generally data is read into buffer from input source, but in some cases pre-loaded buffer is handed to the parser.

protected int
_inputEnd

Index of character after last available one in the buffer.

protected int
_inputPtr

Pointer to next available character in buffer

protected Reader
_inputReader

Input stream that can be used for reading more content, if one in use.

protected final IOContext
_ioContext

I/O context for this reader.

protected int
_maxSpecialChar

Maximum of quote character, linefeeds (\r and \n), escape character.

protected BigDecimal
protected BigInteger
protected double
protected int
protected long
protected String
_numberString

Textual number representation captured from input in cases lazy-parsing is desired.

protected int
_numTypesValid

Bitfield that indicates which numeric representations have been calculated for the current type

protected final CsvParser
_owner

Unfortunate back reference, needed for error reporting

protected int
_pendingLF

Marker to indicate that a linefeed was encountered and now needs to be handled (indicates end-of-record).

protected int
protected int
protected boolean
protected final TextBuffer
_textBuffer

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

protected int
_tokenInputCol

Column on input row that current token starts; 0-based (although in the end it'll be converted to 1-based)

protected int
_tokenInputRow

Input row on which current token starts, 1-based

protected long
_tokenInputTotal

Total number of bytes/characters read before start of current token.

protected boolean
_trimSpaces

Configuration flag that determines whether spaces surrounding separator characters are to be automatically trimmed or not.

pack-priv static final BigDecimal
pack-priv static final BigDecimal
pack-priv static final BigDecimal
pack-priv static final BigDecimal
pack-priv static final BigInteger
pack-priv static final BigInteger
pack-priv static final BigInteger
pack-priv static final BigInteger
protected static final char
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
private static final int
protected static final int
protected static final int
protected static final int
private static final int
protected static final int
protected static final int
private static final int
pack-priv static final double
pack-priv static final long
pack-priv static final double
pack-priv static final double
pack-priv static final long
pack-priv static final double
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int

Constructor Summary

AccessConstructor and Description
public
CsvDecoder(CsvParser owner, IOContext ctxt, Reader r, CsvSchema schema, TextBuffer textBuffer, int stdFeatures, int csvFeatures)

Method Summary

Modifier and TypeMethod and Description
protected void
protected BigDecimal
_getBigDecimal()

Internal accessor that needs to be used for accessing number value of type BigDecimal which -- as of 2.14 -- is typically lazily parsed.

protected BigInteger
_getBigInteger()

Internal accessor that needs to be used for accessing number value of type BigInteger which -- as of 2.14 -- is typically lazily parsed.

protected static final String
_getCharDesc(int ch)

protected final void
protected final int
protected String
protected String
_nextUnquotedString(char[] outBuf, int outPtr)

protected void
protected void
_parseNumericValue(boolean
Whether to try to retain the highest precision for floating-point values or not
exactNumber
)

Method that will parse actual numeric value out of a syntactically valid number value.

private final void
_parseSlowFloatValue(boolean exactNumber)

private final void
_parseSlowIntValue(char[] buf, int offset, int len, boolean neg)

protected final void
_reportError(String msg)

Method for reporting low-level decoding (parsing) problems

private void
public boolean
protected final int
private void
protected char
public JsonReadContext
public JsonReadContext
public void
protected final JsonParseException
protected void
protected void
protected void
protected void
protected void
public BigInteger
public final int
public JsonLocation
public final int
public BigDecimal
public double
public float
public Object
public int
public long
public JsonParser.NumberType
public Number
getNumberValue(boolean
Whether we should try to retain maximum precision or not; passed as true by getNumberValueExact(), and as false by regular getNumberValue).
exact
)

public String
protected final long
protected final int
protected final int
public JsonLocation
public boolean
hasMoreInput()

Method that can be called to see if there is at least one more character to be parsed.

public boolean
public final boolean

Returns:

True if the current token has been quoted, false otherwise
isCurrentTokenQuoted
()

Tell if the current token has been quoted or not.

public boolean
isExpectedNumberIntToken()

Method used by CsvParser#isExpectedNumberIntToken() to coerce current token into integer number, if it looks like one.

protected final boolean
private boolean
public JsonToken
public JsonToken
public String

Returns:

Column value if more found; null to indicate end of line of input
nextString
()

Method called to parse the next token when we don't have any type information, so that all tokens are exposed as basic String values.

public JsonToken
public void
overrideFormatFeatures(int csvFeatures)

public int
protected void
protected void
protected void
protected void
protected void
public void
public boolean
skipLine()

Method called to blindly skip a single line of content, without considering aspects like quoting or escaping.

public boolean

Returns:

false if the end of input was reached
skipLinesWhenNeeded
()

Optionally skip lines that are empty or are comments, depending on the feature activated in the parser

public boolean

Returns:

True if there is a new data line to handle; false if not
startNewLine
()

Method called to handle details of starting a new line, which may include skipping a linefeed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_allowCommentsback to summary
protected boolean _allowComments
_autoCloseInputback to summary
protected boolean _autoCloseInput
_bufferRecyclableback to summary
protected boolean _bufferRecyclable

Flag that indicates whether the input buffer is recycable (and needs to be returned to recycler once we are done) or not.

If it is not, it also means that parser can NOT modify underlying buffer.

_closedback to summary
protected boolean _closed

Flag that indicates whether parser is closed or not. Gets set when parser is either closed by explicit call (close) or when end-of-input is reached.

_currInputProcessedback to summary
protected long _currInputProcessed

Number of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer).

_currInputQuotedback to summary
protected boolean _currInputQuoted

Flag that indicates whether the current token has been quoted or not.

Since
2.18
_currInputRowback to summary
protected int _currInputRow

Current row location of current point in input buffer, starting from 1, if available.

_currInputRowStartback to summary
protected int _currInputRowStart

Current index of the first character of the current row in input buffer. Needed to calculate column position, if necessary; benefit of not having column itself is that this only has to be updated once per line.

_escapeCharback to summary
protected int _escapeChar
_inputBufferback to summary
protected char[] _inputBuffer

Current buffer from which data is read; generally data is read into buffer from input source, but in some cases pre-loaded buffer is handed to the parser.

_inputEndback to summary
protected int _inputEnd

Index of character after last available one in the buffer.

_inputPtrback to summary
protected int _inputPtr

Pointer to next available character in buffer

_inputReaderback to summary
protected Reader _inputReader

Input stream that can be used for reading more content, if one in use. May be null, if input comes just as a full buffer, or if the stream has been closed.

Note

renamed in 2.13 from _inputSource.

_ioContextback to summary
protected final IOContext _ioContext

I/O context for this reader. It handles buffer allocation for the reader.

_maxSpecialCharback to summary
protected int _maxSpecialChar

Maximum of quote character, linefeeds (\r and \n), escape character.

_numberBigDecimalback to summary
protected BigDecimal _numberBigDecimal
_numberBigIntback to summary
protected BigInteger _numberBigInt
_numberDoubleback to summary
protected double _numberDouble
_numberIntback to summary
protected int _numberInt
_numberLongback to summary
protected long _numberLong
_numberStringback to summary
protected String _numberString

Textual number representation captured from input in cases lazy-parsing is desired.

As of 2.14, this only applies to BigInteger and BigDecimal.

Since
2.14
_numTypesValidback to summary
protected int _numTypesValid

Bitfield that indicates which numeric representations have been calculated for the current type

_ownerback to summary
protected final CsvParser _owner

Unfortunate back reference, needed for error reporting

_pendingLFback to summary
protected int _pendingLF

Marker to indicate that a linefeed was encountered and now needs to be handled (indicates end-of-record).

_quoteCharback to summary
protected int _quoteChar
_separatorCharback to summary
protected int _separatorChar
_skipBlankLinesback to summary
protected boolean _skipBlankLines
Since
2.10.1
_textBufferback to summary
protected final TextBuffer _textBuffer

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

_tokenInputColback to summary
protected int _tokenInputCol

Column on input row that current token starts; 0-based (although in the end it'll be converted to 1-based)

_tokenInputRowback to summary
protected int _tokenInputRow

Input row on which current token starts, 1-based

_tokenInputTotalback to summary
protected long _tokenInputTotal

Total number of bytes/characters read before start of current token. For big (gigabyte-sized) sizes are possible, needs to be long, unlike pointers and sizes related to in-memory buffers.

_trimSpacesback to summary
protected boolean _trimSpaces

Configuration flag that determines whether spaces surrounding separator characters are to be automatically trimmed or not.

BD_MAX_INTback to summary
pack-priv static final BigDecimal BD_MAX_INT
BD_MAX_LONGback to summary
pack-priv static final BigDecimal BD_MAX_LONG
BD_MIN_INTback to summary
pack-priv static final BigDecimal BD_MIN_INT
BD_MIN_LONGback to summary
pack-priv static final BigDecimal BD_MIN_LONG
BI_MAX_INTback to summary
pack-priv static final BigInteger BI_MAX_INT
BI_MAX_LONGback to summary
pack-priv static final BigInteger BI_MAX_LONG
BI_MIN_INTback to summary
pack-priv static final BigInteger BI_MIN_INT
BI_MIN_LONGback to summary
pack-priv static final BigInteger BI_MIN_LONG
CHAR_NULLback to summary
protected static final char CHAR_NULL
INT_0back to summary
protected static final int INT_0
INT_1back to summary
protected static final int INT_1
INT_2back to summary
protected static final int INT_2
INT_3back to summary
protected static final int INT_3
INT_4back to summary
protected static final int INT_4
INT_5back to summary
protected static final int INT_5
INT_6back to summary
protected static final int INT_6
INT_7back to summary
protected static final int INT_7
INT_8back to summary
protected static final int INT_8
INT_9back to summary
protected static final int INT_9
INT_CRback to summary
private static final int INT_CR
INT_DECIMAL_POINTback to summary
protected static final int INT_DECIMAL_POINT
INT_eback to summary
protected static final int INT_e
INT_Eback to summary
protected static final int INT_E
INT_LFback to summary
private static final int INT_LF
INT_MINUSback to summary
protected static final int INT_MINUS
INT_PLUSback to summary
protected static final int INT_PLUS
INT_SPACEback to summary
private static final int INT_SPACE
MAX_INT_Dback to summary
pack-priv static final double MAX_INT_D
MAX_INT_Lback to summary
pack-priv static final long MAX_INT_L
MAX_LONG_Dback to summary
pack-priv static final double MAX_LONG_D
MIN_INT_Dback to summary
pack-priv static final double MIN_INT_D
MIN_INT_Lback to summary
pack-priv static final long MIN_INT_L
MIN_LONG_Dback to summary
pack-priv static final double MIN_LONG_D
NR_BIGDECIMALback to summary
protected static final int NR_BIGDECIMAL
NR_BIGINTback to summary
protected static final int NR_BIGINT
NR_DOUBLEback to summary
protected static final int NR_DOUBLE
NR_INTback to summary
protected static final int NR_INT
NR_LONGback to summary
protected static final int NR_LONG
NR_UNKNOWNback to summary
protected static final int NR_UNKNOWN

Constructor Detail

CsvDecoderback to summary
public CsvDecoder(CsvParser owner, IOContext ctxt, Reader r, CsvSchema schema, TextBuffer textBuffer, int stdFeatures, int csvFeatures)

Method Detail

_closeInputback to summary
protected void _closeInput() throws IOException
_getBigDecimalback to summary
protected BigDecimal _getBigDecimal() throws IOException

Internal accessor that needs to be used for accessing number value of type BigDecimal which -- as of 2.14 -- is typically lazily parsed.

Since
2.14
_getBigIntegerback to summary
protected BigInteger _getBigInteger() throws IOException

Internal accessor that needs to be used for accessing number value of type BigInteger which -- as of 2.14 -- is typically lazily parsed.

Since
2.14
_getCharDescback to summary
protected static final String _getCharDesc(int ch)
_handleLFback to summary
protected final void _handleLF() throws IOException
_nextCharback to summary
protected final int _nextChar() throws IOException
_nextQuotedStringback to summary
protected String _nextQuotedString() throws IOException
_nextUnquotedStringback to summary
protected String _nextUnquotedString(char[] outBuf, int outPtr) throws IOException
_parseIntValueback to summary
protected void _parseIntValue() throws IOException
_parseNumericValueback to summary
protected void _parseNumericValue(boolean exactNumber) throws IOException

Method that will parse actual numeric value out of a syntactically valid number value. Type it will parse into depends on whether it is a floating point number, as well as its magnitude: smallest legal type (of ones available) is used for efficiency.

Parameters
exactNumber:boolean

Whether to try to retain the highest precision for floating-point values or not

_parseSlowFloatValueback to summary
private final void _parseSlowFloatValue(boolean exactNumber) throws IOException
_parseSlowIntValueback to summary
private final void _parseSlowIntValue(char[] buf, int offset, int len, boolean neg) throws IOException
_reportErrorback to summary
protected final void _reportError(String msg) throws JsonParseException

Method for reporting low-level decoding (parsing) problems

_skipCommentContentsback to summary
private void _skipCommentContents() throws IOException
_skipCommentLinesback to summary
public boolean _skipCommentLines() throws IOException
_skipLeadingSpaceback to summary
protected final int _skipLeadingSpace() throws IOException
_throwInternalback to summary
private void _throwInternal()
_unescapeback to summary
protected char _unescape() throws IOException
childArrayContextback to summary
public JsonReadContext childArrayContext(JsonReadContext context)
childObjectContextback to summary
public JsonReadContext childObjectContext(JsonReadContext context)
closeback to summary
public void close() throws IOException
constructErrorback to summary
protected final JsonParseException constructError(String msg, Throwable t)
convertNumberToBigDecimalback to summary
protected void convertNumberToBigDecimal() throws IOException
convertNumberToBigIntegerback to summary
protected void convertNumberToBigInteger() throws IOException
convertNumberToDoubleback to summary
protected void convertNumberToDouble() throws IOException
convertNumberToIntback to summary
protected void convertNumberToInt() throws IOException
convertNumberToLongback to summary
protected void convertNumberToLong() throws IOException
getBigIntegerValueback to summary
public BigInteger getBigIntegerValue() throws IOException
getCurrentColumnback to summary
public final int getCurrentColumn()
getCurrentLocationback to summary
public JsonLocation getCurrentLocation()
getCurrentRowback to summary
public final int getCurrentRow()
getDecimalValueback to summary
public BigDecimal getDecimalValue() throws IOException
getDoubleValueback to summary
public double getDoubleValue() throws IOException
getFloatValueback to summary
public float getFloatValue() throws IOException
getInputSourceback to summary
public Object getInputSource()
getIntValueback to summary
public int getIntValue() throws IOException
getLongValueback to summary
public long getLongValue() throws IOException
getNumberTypeback to summary
public JsonParser.NumberType getNumberType() throws IOException
getNumberValueback to summary
public Number getNumberValue(boolean exact) throws IOException
Parameters
exact:boolean

Whether we should try to retain maximum precision or not; passed as true by getNumberValueExact(), and as false by regular getNumberValue).

getTextback to summary
public String getText() throws IOException
getTokenCharacterOffsetback to summary
protected final long getTokenCharacterOffset()
getTokenColumnNrback to summary
protected final int getTokenColumnNr()
getTokenLineNrback to summary
protected final int getTokenLineNr()
getTokenLocationback to summary
public JsonLocation getTokenLocation()
hasMoreInputback to summary
public boolean hasMoreInput() throws IOException

Method that can be called to see if there is at least one more character to be parsed.

isClosedback to summary
public boolean isClosed()
isCurrentTokenQuotedback to summary
public final boolean isCurrentTokenQuoted()

Tell if the current token has been quoted or not.

Returns:boolean

True if the current token has been quoted, false otherwise

Since
2.18
isExpectedNumberIntTokenback to summary
public boolean isExpectedNumberIntToken() throws IOException

Method used by CsvParser#isExpectedNumberIntToken() to coerce current token into integer number, if it looks like one.

Since
2.12
loadMoreback to summary
protected final boolean loadMore() throws IOException
looksLikeIntback to summary
private boolean looksLikeInt() throws IOException
nextNumberback to summary
public JsonToken nextNumber() throws IOException
nextNumberOrStringback to summary
public JsonToken nextNumberOrString() throws IOException
nextStringback to summary
public String nextString() throws IOException

Method called to parse the next token when we don't have any type information, so that all tokens are exposed as basic String values.

Returns:String

Column value if more found; null to indicate end of line of input

nextStringOrLiteralback to summary
public JsonToken nextStringOrLiteral() throws IOException
overrideFormatFeaturesback to summary
public void overrideFormatFeatures(int csvFeatures)
Since
2.7
releaseBufferedback to summary
public int releaseBuffered(Writer out) throws IOException
releaseBuffersback to summary
protected void releaseBuffers() throws IOException
reportInvalidNumberback to summary
protected void reportInvalidNumber(String msg) throws JsonParseException
reportOverflowIntback to summary
protected void reportOverflowInt() throws IOException
reportOverflowLongback to summary
protected void reportOverflowLong() throws IOException
reportUnexpectedNumberCharback to summary
protected void reportUnexpectedNumberChar(int ch, String comment) throws JsonParseException
setSchemaback to summary
public void setSchema(CsvSchema schema)
skipLineback to summary
public boolean skipLine() throws IOException

Method called to blindly skip a single line of content, without considering aspects like quoting or escaping. Used currently simply to skip the first line of input document, if instructed to do so.

skipLinesWhenNeededback to summary
public boolean skipLinesWhenNeeded() throws IOException

Optionally skip lines that are empty or are comments, depending on the feature activated in the parser

Returns:boolean

false if the end of input was reached

Since
2.10.1
startNewLineback to summary
public boolean startNewLine() throws IOException

Method called to handle details of starting a new line, which may include skipping a linefeed.

Returns:boolean

True if there is a new data line to handle; false if not