Class CsvDecoder
- java.lang.Object
-
- com.fasterxml.jackson.dataformat.csv.impl.CsvDecoder
-
public class CsvDecoder extends java.lang.ObjectLow-level helper class that handles actual reading of CSV, purely based on indexes given without worrying about reordering etc.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_allowCommentsprotected boolean_autoCloseInputprotected boolean_bufferRecyclableFlag that indicates whether the input buffer is recycable (and needs to be returned to recycler once we are done) or not.protected boolean_closedFlag that indicates whether parser is closed or not.protected long_currInputProcessedNumber of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer).protected int_currInputRowCurrent row location of current point in input buffer, starting from 1, if available.protected int_currInputRowStartCurrent index of the first character of the current row in input buffer.protected int_escapeCharprotected 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.protected int_inputEndIndex of character after last available one in the buffer.protected int_inputPtrPointer to next available character in bufferprotected java.io.Reader_inputSourceInput stream that can be used for reading more content, if one in use.protected com.fasterxml.jackson.core.io.IOContext_ioContextI/O context for this reader.protected int_maxSpecialCharMaximum of quote character, linefeeds (\r and \n), escape character.protected java.math.BigDecimal_numberBigDecimalprotected java.math.BigInteger_numberBigIntprotected double_numberDoubleprotected int_numberIntprotected long_numberLongprotected int_numTypesValidBitfield that indicates which numeric representations have been calculated for the current typeprotected CsvParser_ownerUnfortunate back reference, needed for error reportingprotected int_pendingLFMarker to indicate that a linefeed was encountered and now needs to be handled (indicates end-of-record).protected int_quoteCharprotected int_separatorCharprotected TextBuffer_textBufferBuffer that contains contents of all values after processing of doubled-quotes, escaped characters.protected int_tokenInputColColumn on input row that current token starts; 0-based (although in the end it'll be converted to 1-based)protected int_tokenInputRowInput row on which current token starts, 1-basedprotected long_tokenInputTotalTotal number of bytes/characters read before start of current token.protected boolean_trimSpacesConfiguration flag that determines whether spaces surrounding separator characters are to be automatically trimmed or not.protected static charCHAR_NULLprotected static intINT_0protected static intINT_1protected static intINT_2protected static intINT_3protected static intINT_4protected static intINT_5protected static intINT_6protected static intINT_7protected static intINT_8protected static intINT_9protected static intINT_DECIMAL_POINTprotected static intINT_eprotected static intINT_Eprotected static intINT_MINUSprotected static intINT_PLUSprotected static intNR_BIGDECIMALprotected static intNR_BIGINTprotected static intNR_DOUBLEprotected static intNR_INTprotected static intNR_LONGprotected static intNR_UNKNOWN
-
Constructor Summary
Constructors Constructor Description CsvDecoder(CsvParser owner, com.fasterxml.jackson.core.io.IOContext ctxt, java.io.Reader r, CsvSchema schema, TextBuffer textBuffer, int stdFeatures, int csvFeatures)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_closeInput()protected static java.lang.String_getCharDesc(int ch)protected void_handleLF()protected int_nextChar()protected java.lang.String_nextQuotedString()protected java.lang.String_nextUnquotedString(char[] outBuf, int outPtr)protected void_parseNumericValue(int expType)Method that will parse actual numeric value out of a syntactically valid number value.protected void_reportError(java.lang.String msg)Method for reporting low-level decoding (parsing) problemsprotected int_skipCommentLines()protected int_skipLeadingSpace()protected char_unescape()com.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 com.fasterxml.jackson.core.JsonParseExceptionconstructError(java.lang.String msg, java.lang.Throwable t)protected voidconvertNumberToBigDecimal()protected voidconvertNumberToBigInteger()protected voidconvertNumberToDouble()protected voidconvertNumberToInt()protected voidconvertNumberToLong()java.math.BigIntegergetBigIntegerValue()intgetCurrentColumn()com.fasterxml.jackson.core.JsonLocationgetCurrentLocation()intgetCurrentRow()java.math.BigDecimalgetDecimalValue()doublegetDoubleValue()floatgetFloatValue()java.lang.ObjectgetInputSource()intgetIntValue()longgetLongValue()com.fasterxml.jackson.core.JsonParser.NumberTypegetNumberType()java.lang.NumbergetNumberValue()java.lang.StringgetText()protected longgetTokenCharacterOffset()protected intgetTokenColumnNr()protected intgetTokenLineNr()com.fasterxml.jackson.core.JsonLocationgetTokenLocation()booleanhasMoreInput()Method that can be called to see if there is at least one more character to be parsed.booleanisClosed()protected booleanloadMore()com.fasterxml.jackson.core.JsonTokennextNumber()com.fasterxml.jackson.core.JsonTokennextNumberOrString()java.lang.StringnextString()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.com.fasterxml.jackson.core.JsonTokennextStringOrLiteral()voidoverrideFormatFeatures(int csvFeatures)intreleaseBuffered(java.io.Writer out)protected voidreleaseBuffers()protected voidreportInvalidNumber(java.lang.String msg)protected voidreportOverflowInt()protected voidreportOverflowLong()protected voidreportUnexpectedNumberChar(int ch, java.lang.String comment)voidsetSchema(CsvSchema schema)voidskipLeadingComments()booleanskipLine()Method called to blindly skip a single line of content, without considering aspects like quoting or escaping.booleanstartNewLine()Method called to handle details of starting a new line, which may include skipping a linefeed.
-
-
-
Field Detail
-
_owner
protected final CsvParser _owner
Unfortunate back reference, needed for error reporting
-
_ioContext
protected final com.fasterxml.jackson.core.io.IOContext _ioContext
I/O context for this reader. It handles buffer allocation for the reader.
-
_inputSource
protected java.io.Reader _inputSource
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.
-
_bufferRecyclable
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.
-
_autoCloseInput
protected boolean _autoCloseInput
-
_trimSpaces
protected boolean _trimSpaces
Configuration flag that determines whether spaces surrounding separator characters are to be automatically trimmed or not.
-
_allowComments
protected boolean _allowComments
-
_maxSpecialChar
protected int _maxSpecialChar
Maximum of quote character, linefeeds (\r and \n), escape character.
-
_separatorChar
protected int _separatorChar
-
_quoteChar
protected int _quoteChar
-
_escapeChar
protected int _escapeChar
-
_textBuffer
protected final TextBuffer _textBuffer
Buffer that contains contents of all values after processing of doubled-quotes, escaped characters.
-
_inputBuffer
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.
-
_inputPtr
protected int _inputPtr
Pointer to next available character in buffer
-
_inputEnd
protected int _inputEnd
Index of character after last available one in the buffer.
-
_pendingLF
protected int _pendingLF
Marker to indicate that a linefeed was encountered and now needs to be handled (indicates end-of-record).
-
_closed
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.
-
_currInputProcessed
protected long _currInputProcessed
Number of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer).
-
_currInputRow
protected int _currInputRow
Current row location of current point in input buffer, starting from 1, if available.
-
_currInputRowStart
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.
-
_tokenInputTotal
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.
-
_tokenInputRow
protected int _tokenInputRow
Input row on which current token starts, 1-based
-
_tokenInputCol
protected int _tokenInputCol
Column 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:
- Constant Field Values
-
NR_INT
protected static final int NR_INT
- See Also:
- Constant Field Values
-
NR_LONG
protected static final int NR_LONG
- See Also:
- Constant Field Values
-
NR_BIGINT
protected static final int NR_BIGINT
- See Also:
- Constant Field Values
-
NR_DOUBLE
protected static final int NR_DOUBLE
- See Also:
- Constant Field Values
-
NR_BIGDECIMAL
protected static final int NR_BIGDECIMAL
- See Also:
- Constant Field Values
-
INT_0
protected static final int INT_0
- See Also:
- Constant Field Values
-
INT_1
protected static final int INT_1
- See Also:
- Constant Field Values
-
INT_2
protected static final int INT_2
- See Also:
- Constant Field Values
-
INT_3
protected static final int INT_3
- See Also:
- Constant Field Values
-
INT_4
protected static final int INT_4
- See Also:
- Constant Field Values
-
INT_5
protected static final int INT_5
- See Also:
- Constant Field Values
-
INT_6
protected static final int INT_6
- See Also:
- Constant Field Values
-
INT_7
protected static final int INT_7
- See Also:
- Constant Field Values
-
INT_8
protected static final int INT_8
- See Also:
- Constant Field Values
-
INT_9
protected static final int INT_9
- See Also:
- Constant Field Values
-
INT_MINUS
protected static final int INT_MINUS
- See Also:
- Constant Field Values
-
INT_PLUS
protected static final int INT_PLUS
- See Also:
- Constant Field Values
-
INT_DECIMAL_POINT
protected static final int INT_DECIMAL_POINT
- See Also:
- Constant Field Values
-
INT_e
protected static final int INT_e
- See Also:
- Constant Field Values
-
INT_E
protected static final int INT_E
- See Also:
- Constant Field Values
-
CHAR_NULL
protected static final char CHAR_NULL
- See Also:
- Constant Field Values
-
_numTypesValid
protected int _numTypesValid
Bitfield 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
protected java.math.BigInteger _numberBigInt
-
_numberBigDecimal
protected java.math.BigDecimal _numberBigDecimal
-
-
Constructor Detail
-
CsvDecoder
public CsvDecoder(CsvParser owner, com.fasterxml.jackson.core.io.IOContext ctxt, java.io.Reader r, CsvSchema schema, TextBuffer textBuffer, int stdFeatures, int csvFeatures)
-
-
Method Detail
-
setSchema
public void setSchema(CsvSchema schema)
-
overrideFormatFeatures
public void overrideFormatFeatures(int csvFeatures)
- Since:
- 2.7
-
getInputSource
public java.lang.Object getInputSource()
-
isClosed
public boolean isClosed()
-
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
releaseBuffered
public int releaseBuffered(java.io.Writer out) throws java.io.IOException- Throws:
java.io.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()
-
getTokenCharacterOffset
protected final long getTokenCharacterOffset()
-
getTokenLineNr
protected final int getTokenLineNr()
-
getTokenColumnNr
protected final int getTokenColumnNr()
-
releaseBuffers
protected void releaseBuffers() throws java.io.IOException- Throws:
java.io.IOException
-
_closeInput
protected void _closeInput() throws java.io.IOException- Throws:
java.io.IOException
-
loadMore
protected final boolean loadMore() throws java.io.IOException- Throws:
java.io.IOException
-
getText
public java.lang.String getText()
-
hasMoreInput
public boolean hasMoreInput() throws java.io.IOExceptionMethod that can be called to see if there is at least one more character to be parsed.- Throws:
java.io.IOException
-
startNewLine
public boolean startNewLine() throws java.io.IOExceptionMethod 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:
java.io.IOException
-
skipLeadingComments
public void skipLeadingComments() throws java.io.IOException- Throws:
java.io.IOException
-
_skipCommentLines
protected int _skipCommentLines() throws java.io.IOException- Throws:
java.io.IOException
-
skipLine
public boolean skipLine() throws java.io.IOExceptionMethod 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:
java.io.IOException
-
nextString
public java.lang.String nextString() throws java.io.IOExceptionMethod 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:
java.io.IOException
-
nextStringOrLiteral
public com.fasterxml.jackson.core.JsonToken nextStringOrLiteral() throws java.io.IOException- Throws:
java.io.IOException
-
nextNumber
public com.fasterxml.jackson.core.JsonToken nextNumber() throws java.io.IOException- Throws:
java.io.IOException
-
nextNumberOrString
public com.fasterxml.jackson.core.JsonToken nextNumberOrString() throws java.io.IOException- Throws:
java.io.IOException
-
_nextUnquotedString
protected java.lang.String _nextUnquotedString(char[] outBuf, int outPtr) throws java.io.IOException- Throws:
java.io.IOException
-
_nextQuotedString
protected java.lang.String _nextQuotedString() throws java.io.IOException- Throws:
java.io.IOException
-
_handleLF
protected final void _handleLF() throws java.io.IOException- Throws:
java.io.IOException
-
_unescape
protected char _unescape() throws java.io.IOException- Throws:
java.io.IOException
-
_nextChar
protected final int _nextChar() throws java.io.IOException- Throws:
java.io.IOException
-
_skipLeadingSpace
protected final int _skipLeadingSpace() throws java.io.IOException- Throws:
java.io.IOException
-
getNumberValue
public java.lang.Number getNumberValue() throws java.io.IOException- Throws:
java.io.IOException
-
getNumberType
public com.fasterxml.jackson.core.JsonParser.NumberType getNumberType() throws java.io.IOException- Throws:
java.io.IOException
-
getIntValue
public int getIntValue() throws java.io.IOException- Throws:
java.io.IOException
-
getLongValue
public long getLongValue() throws java.io.IOException- Throws:
java.io.IOException
-
getBigIntegerValue
public java.math.BigInteger getBigIntegerValue() throws java.io.IOException- Throws:
java.io.IOException
-
getFloatValue
public float getFloatValue() throws java.io.IOException- Throws:
java.io.IOException
-
getDoubleValue
public double getDoubleValue() throws java.io.IOException- Throws:
java.io.IOException
-
getDecimalValue
public java.math.BigDecimal getDecimalValue() throws java.io.IOException- Throws:
java.io.IOException
-
_parseNumericValue
protected void _parseNumericValue(int expType) throws java.io.IOExceptionMethod 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:
expType- Numeric type that we will immediately need, if any; mostly necessary to optimize handling of floating point numbers- Throws:
java.io.IOException
-
convertNumberToInt
protected void convertNumberToInt() throws java.io.IOException- Throws:
java.io.IOException
-
convertNumberToLong
protected void convertNumberToLong() throws java.io.IOException- Throws:
java.io.IOException
-
convertNumberToBigInteger
protected void convertNumberToBigInteger() throws java.io.IOException- Throws:
java.io.IOException
-
convertNumberToDouble
protected void convertNumberToDouble() throws java.io.IOException- Throws:
java.io.IOException
-
convertNumberToBigDecimal
protected void convertNumberToBigDecimal() throws java.io.IOException- Throws:
java.io.IOException
-
reportUnexpectedNumberChar
protected void reportUnexpectedNumberChar(int ch, java.lang.String comment) throws com.fasterxml.jackson.core.JsonParseException- Throws:
com.fasterxml.jackson.core.JsonParseException
-
reportInvalidNumber
protected void reportInvalidNumber(java.lang.String msg) throws com.fasterxml.jackson.core.JsonParseException- Throws:
com.fasterxml.jackson.core.JsonParseException
-
reportOverflowInt
protected void reportOverflowInt() throws java.io.IOException- Throws:
java.io.IOException
-
reportOverflowLong
protected void reportOverflowLong() throws java.io.IOException- Throws:
java.io.IOException
-
constructError
protected final com.fasterxml.jackson.core.JsonParseException constructError(java.lang.String msg, java.lang.Throwable t)
-
_getCharDesc
protected static final java.lang.String _getCharDesc(int ch)
-
_reportError
protected final void _reportError(java.lang.String msg) throws com.fasterxml.jackson.core.JsonParseExceptionMethod for reporting low-level decoding (parsing) problems- Throws:
com.fasterxml.jackson.core.JsonParseException
-
-