Class CsvDecoder
java.lang.Object
com.fasterxml.jackson.dataformat.csv.impl.CsvDecoder
Low-level helper class that handles actual reading of CSV,
purely based on indexes given without worrying about reordering etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanFlag that indicates whether the input buffer is recycable (and needs to be returned to recycler once we are done) or not.protected booleanFlag that indicates whether parser is closed or not.protected longNumber of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer).protected booleanFlag that indicates whether the current token has been quoted or not.protected intCurrent row location of current point in input buffer, starting from 1, if available.protected intCurrent index of the first character of the current row in input buffer.protected intprotected char[]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 intIndex of character after last available one in the buffer.protected intPointer to next available character in bufferprotected ReaderInput stream that can be used for reading more content, if one in use.protected final com.fasterxml.jackson.core.io.IOContextI/O context for this reader.protected intMaximum of quote character, linefeeds (\r and \n), escape character.protected BigDecimalprotected BigIntegerprotected doubleprotected intprotected longprotected StringTextual number representation captured from input in cases lazy-parsing is desired.protected intBitfield that indicates which numeric representations have been calculated for the current typeprotected final CsvParserUnfortunate back reference, needed for error reportingprotected intMarker to indicate that a linefeed was encountered and now needs to be handled (indicates end-of-record).protected intprotected intprotected booleanprotected final com.fasterxml.jackson.core.util.TextBufferBuffer that contains contents of all values after processing of doubled-quotes, escaped characters.protected intColumn on input row that current token starts; 0-based (although in the end it'll be converted to 1-based)protected intInput row on which current token starts, 1-basedprotected longTotal number of bytes/characters read before start of current token.protected booleanConfiguration flag that determines whether spaces surrounding separator characters are to be automatically trimmed or not.(package private) static final BigDecimal(package private) static final BigDecimal(package private) static final BigDecimal(package private) static final BigDecimalprotected static final charprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprivate static final intprotected static final intprotected static final intprotected static final intprivate static final intprotected static final intprotected static final intprivate static final int(package private) static final double(package private) static final long(package private) static final double(package private) static final double(package private) static final long(package private) static final doubleprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final int -
Constructor Summary
ConstructorsConstructorDescriptionCsvDecoder(CsvParser owner, com.fasterxml.jackson.core.io.IOContext ctxt, Reader r, CsvSchema schema, com.fasterxml.jackson.core.util.TextBuffer textBuffer, int stdFeatures, int csvFeatures) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected BigDecimalInternal accessor that needs to be used for accessing number value of typeBigDecimalwhich -- as of 2.14 -- is typically lazily parsed.protected BigIntegerInternal accessor that needs to be used for accessing number value of typeBigIntegerwhich -- as of 2.14 -- is typically lazily parsed.protected static final String_getCharDesc(int ch) protected final voidprotected final intprotected Stringprotected String_nextUnquotedString(char[] outBuf, int outPtr) protected voidprotected void_parseNumericValue(boolean 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) problemsprivate voidbooleanprotected final intprivate voidprotected charcom.fasterxml.jackson.core.json.JsonReadContextchildArrayContext(com.fasterxml.jackson.core.json.JsonReadContext context) com.fasterxml.jackson.core.json.JsonReadContextchildObjectContext(com.fasterxml.jackson.core.json.JsonReadContext context) voidclose()protected final com.fasterxml.jackson.core.JsonParseExceptionconstructError(String msg, Throwable t) protected voidprotected voidprotected voidprotected voidprotected voidfinal intcom.fasterxml.jackson.core.JsonLocationfinal intdoublefloatintlongcom.fasterxml.jackson.core.JsonParser.NumberTypegetNumberValue(boolean exact) getText()protected final longprotected final intprotected final intcom.fasterxml.jackson.core.JsonLocationbooleanMethod that can be called to see if there is at least one more character to be parsed.booleanisClosed()final booleanTell if the current token has been quoted or not.booleanMethod used byCsvParser.isExpectedNumberIntToken()to coerce current token into integer number, if it looks like one.protected final booleanloadMore()private booleancom.fasterxml.jackson.core.JsonTokencom.fasterxml.jackson.core.JsonTokenMethod called to parse the next token when we don't have any type information, so that all tokens are exposed as basic String values.com.fasterxml.jackson.core.JsonTokenvoidoverrideFormatFeatures(int csvFeatures) intreleaseBuffered(Writer out) protected voidprotected voidprotected voidprotected voidprotected voidreportUnexpectedNumberChar(int ch, String comment) voidbooleanskipLine()Method called to blindly skip a single line of content, without considering aspects like quoting or escaping.booleanOptionally skip lines that are empty or are comments, depending on the feature activated in the parserbooleanMethod called to handle details of starting a new line, which may include skipping a linefeed.
-
Field Details
-
INT_SPACE
private static final int INT_SPACE- See Also:
-
INT_CR
private static final int INT_CR- See Also:
-
INT_LF
private static final int INT_LF- See Also:
-
_owner
Unfortunate back reference, needed for error reporting -
_ioContext
protected final com.fasterxml.jackson.core.io.IOContext _ioContextI/O context for this reader. It handles buffer allocation for the 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. -
_bufferRecyclable
protected boolean _bufferRecyclableFlag 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.
-
_autoCloseInput
protected boolean _autoCloseInput -
_trimSpaces
protected boolean _trimSpacesConfiguration flag that determines whether spaces surrounding separator characters are to be automatically trimmed or not. -
_allowComments
protected boolean _allowComments -
_skipBlankLines
protected boolean _skipBlankLines- Since:
- 2.10.1
-
_maxSpecialChar
protected int _maxSpecialCharMaximum of quote character, linefeeds (\r and \n), escape character. -
_separatorChar
protected int _separatorChar -
_quoteChar
protected int _quoteChar -
_escapeChar
protected int _escapeChar -
_textBuffer
protected final com.fasterxml.jackson.core.util.TextBuffer _textBufferBuffer that contains contents of all values after processing of doubled-quotes, escaped characters. -
_inputBuffer
protected char[] _inputBufferCurrent 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. -
_inputPtr
protected int _inputPtrPointer to next available character in buffer -
_inputEnd
protected int _inputEndIndex of character after last available one in the buffer. -
_pendingLF
protected int _pendingLFMarker to indicate that a linefeed was encountered and now needs to be handled (indicates end-of-record). -
_closed
protected boolean _closedFlag 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. -
_currInputProcessed
protected long _currInputProcessedNumber of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer). -
_currInputRow
protected int _currInputRowCurrent row location of current point in input buffer, starting from 1, if available. -
_currInputRowStart
protected int _currInputRowStartCurrent 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. -
_currInputQuoted
protected boolean _currInputQuotedFlag that indicates whether the current token has been quoted or not.- Since:
- 2.18
-
_tokenInputTotal
protected long _tokenInputTotalTotal 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. -
_tokenInputRow
protected int _tokenInputRowInput row on which current token starts, 1-based -
_tokenInputCol
protected int _tokenInputColColumn on input row that current token starts; 0-based (although in the end it'll be converted to 1-based) -
NR_UNKNOWN
protected static final int NR_UNKNOWN- See Also:
-
NR_INT
protected static final int NR_INT- See Also:
-
NR_LONG
protected static final int NR_LONG- See Also:
-
NR_BIGINT
protected static final int NR_BIGINT- See Also:
-
NR_DOUBLE
protected static final int NR_DOUBLE- See Also:
-
NR_BIGDECIMAL
protected static final int NR_BIGDECIMAL- See Also:
-
BD_MIN_LONG
-
BD_MAX_LONG
-
BD_MIN_INT
-
BD_MAX_INT
-
MIN_INT_L
static final long MIN_INT_L- See Also:
-
MAX_INT_L
static final long MAX_INT_L- See Also:
-
MIN_LONG_D
static final double MIN_LONG_D- See Also:
-
MAX_LONG_D
static final double MAX_LONG_D- See Also:
-
MIN_INT_D
static final double MIN_INT_D- See Also:
-
MAX_INT_D
static final double MAX_INT_D- See Also:
-
INT_0
protected static final int INT_0- See Also:
-
INT_1
protected static final int INT_1- See Also:
-
INT_2
protected static final int INT_2- See Also:
-
INT_3
protected static final int INT_3- See Also:
-
INT_4
protected static final int INT_4- See Also:
-
INT_5
protected static final int INT_5- See Also:
-
INT_6
protected static final int INT_6- See Also:
-
INT_7
protected static final int INT_7- See Also:
-
INT_8
protected static final int INT_8- See Also:
-
INT_9
protected static final int INT_9- See Also:
-
INT_MINUS
protected static final int INT_MINUS- See Also:
-
INT_PLUS
protected static final int INT_PLUS- See Also:
-
INT_DECIMAL_POINT
protected static final int INT_DECIMAL_POINT- See Also:
-
INT_e
protected static final int INT_e- See Also:
-
INT_E
protected static final int INT_E- See Also:
-
CHAR_NULL
protected static final char CHAR_NULL- See Also:
-
_numTypesValid
protected int _numTypesValidBitfield that indicates which numeric representations have been calculated for the current type -
_numberInt
protected int _numberInt -
_numberLong
protected long _numberLong -
_numberDouble
protected double _numberDouble -
_numberBigInt
-
_numberBigDecimal
-
_numberString
Textual number representation captured from input in cases lazy-parsing is desired.As of 2.14, this only applies to
BigIntegerandBigDecimal.- Since:
- 2.14
-
-
Constructor Details
-
CsvDecoder
-
-
Method Details
-
setSchema
-
overrideFormatFeatures
public void overrideFormatFeatures(int csvFeatures) - Since:
- 2.7
-
getInputSource
-
isClosed
public boolean isClosed() -
close
- Throws:
IOException
-
releaseBuffered
- Throws:
IOException
-
childArrayContext
public com.fasterxml.jackson.core.json.JsonReadContext childArrayContext(com.fasterxml.jackson.core.json.JsonReadContext context) -
childObjectContext
public com.fasterxml.jackson.core.json.JsonReadContext childObjectContext(com.fasterxml.jackson.core.json.JsonReadContext context) -
getTokenLocation
public com.fasterxml.jackson.core.JsonLocation getTokenLocation() -
getCurrentLocation
public com.fasterxml.jackson.core.JsonLocation getCurrentLocation() -
getCurrentRow
public final int getCurrentRow() -
getCurrentColumn
public final int getCurrentColumn() -
isCurrentTokenQuoted
public final boolean isCurrentTokenQuoted()Tell if the current token has been quoted or not.- Returns:
- True if the current token has been quoted, false otherwise
- Since:
- 2.18
-
getTokenCharacterOffset
protected final long getTokenCharacterOffset() -
getTokenLineNr
protected final int getTokenLineNr() -
getTokenColumnNr
protected final int getTokenColumnNr() -
releaseBuffers
- Throws:
IOException
-
_closeInput
- Throws:
IOException
-
loadMore
- Throws:
IOException
-
getText
- Throws:
IOException
-
hasMoreInput
Method that can be called to see if there is at least one more character to be parsed.- Throws:
IOException
-
startNewLine
Method called to handle details of starting a new line, which may include skipping a linefeed.- Returns:
- True if there is a new data line to handle; false if not
- Throws:
IOException
-
skipLinesWhenNeeded
Optionally skip lines that are empty or are comments, depending on the feature activated in the parser- Returns:
- false if the end of input was reached
- Throws:
IOException- Since:
- 2.10.1
-
_skipCommentLines
- Throws:
IOException
-
_skipCommentContents
- Throws:
IOException
-
skipLine
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.- Throws:
IOException
-
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.- Returns:
- Column value if more found; null to indicate end of line of input
- Throws:
IOException
-
nextStringOrLiteral
- Throws:
IOException
-
nextNumber
- Throws:
IOException
-
nextNumberOrString
- Throws:
IOException
-
_nextUnquotedString
- Throws:
IOException
-
_nextQuotedString
- Throws:
IOException
-
_handleLF
- Throws:
IOException
-
_unescape
- Throws:
IOException
-
_nextChar
- Throws:
IOException
-
_skipLeadingSpace
- Throws:
IOException
-
isExpectedNumberIntToken
Method used byCsvParser.isExpectedNumberIntToken()to coerce current token into integer number, if it looks like one.- Throws:
IOException- Since:
- 2.12
-
getNumberValue
- Parameters:
exact- Whether we should try to retain maximum precision or not; passed astruebygetNumberValueExact(), and asfalseby regulargetNumberValue).- Throws:
IOException
-
getNumberType
- Throws:
IOException
-
getIntValue
- Throws:
IOException
-
getLongValue
- Throws:
IOException
-
getBigIntegerValue
- Throws:
IOException
-
getFloatValue
- Throws:
IOException
-
getDoubleValue
- Throws:
IOException
-
getDecimalValue
- Throws:
IOException
-
_getBigInteger
Internal accessor that needs to be used for accessing number value of typeBigIntegerwhich -- as of 2.14 -- is typically lazily parsed.- Throws:
IOException- Since:
- 2.14
-
_getBigDecimal
Internal accessor that needs to be used for accessing number value of typeBigDecimalwhich -- as of 2.14 -- is typically lazily parsed.- Throws:
IOException- Since:
- 2.14
-
_parseNumericValue
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- Whether to try to retain the highest precision for floating-point values or not- Throws:
IOException
-
looksLikeInt
- Throws:
IOException
-
_parseIntValue
- Throws:
IOException
-
_parseSlowFloatValue
- Throws:
IOException
-
_parseSlowIntValue
private final void _parseSlowIntValue(char[] buf, int offset, int len, boolean neg) throws IOException - Throws:
IOException
-
convertNumberToInt
- Throws:
IOException
-
convertNumberToLong
- Throws:
IOException
-
convertNumberToBigInteger
- Throws:
IOException
-
convertNumberToDouble
- Throws:
IOException
-
convertNumberToBigDecimal
- Throws:
IOException
-
reportUnexpectedNumberChar
protected void reportUnexpectedNumberChar(int ch, String comment) throws com.fasterxml.jackson.core.JsonParseException - Throws:
com.fasterxml.jackson.core.JsonParseException
-
reportInvalidNumber
- Throws:
com.fasterxml.jackson.core.JsonParseException
-
reportOverflowInt
- Throws:
IOException
-
reportOverflowLong
- Throws:
IOException
-
constructError
-
_getCharDesc
-
_throwInternal
private void _throwInternal() -
_reportError
Method for reporting low-level decoding (parsing) problems- Throws:
com.fasterxml.jackson.core.JsonParseException
-