com.fasterxml.jackson.dataformat.csv.impl
Class CsvReader

java.lang.Object
  extended by com.fasterxml.jackson.dataformat.csv.impl.CsvReader

public class CsvReader
extends Object

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


Field Summary
protected  boolean _autoCloseInput
           
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  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 _escapeChar
           
protected  int _expLength
          Length of the exponent part of the number, if any, not including 'e' marker or sign, just digits.
protected  int _fractLength
          Length of the fractional part (not including decimal point or exponent), in characters.
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 _inputSource
          Input stream that can be used for reading more content, if one in use.
protected  int _intLength
          Length of integer part of the number, in characters
protected  com.fasterxml.jackson.core.io.IOContext _ioContext
          I/O context for this reader.
protected  int _maxSpecialChar
          Maximum of quote character, linefeeds (\r and \n), escape character.
protected  BigDecimal _numberBigDecimal
           
protected  BigInteger _numberBigInt
           
protected  double _numberDouble
           
protected  int _numberInt
           
protected  long _numberLong
           
protected  boolean _numberNegative
          Flag that indicates whether numeric value has a negative value.
protected  int _numTypesValid
          Bitfield that indicates which numeric representations have been calculated for the current type
protected  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 _quoteChar
           
protected  int _separatorChar
           
protected  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.
protected static char CHAR_NULL
           
protected static int INT_0
           
protected static int INT_1
           
protected static int INT_2
           
protected static int INT_3
           
protected static int INT_4
           
protected static int INT_5
           
protected static int INT_6
           
protected static int INT_7
           
protected static int INT_8
           
protected static int INT_9
           
protected static int INT_DECIMAL_POINT
           
protected static int INT_e
           
protected static int INT_E
           
protected static int INT_MINUS
           
protected static int INT_PLUS
           
protected static int NR_BIGDECIMAL
           
protected static int NR_BIGINT
           
protected static int NR_DOUBLE
           
protected static int NR_INT
           
protected static int NR_LONG
           
protected static int NR_UNKNOWN
           
 
Constructor Summary
CsvReader(CsvParser owner, com.fasterxml.jackson.core.io.IOContext ctxt, Reader r, CsvSchema schema, TextBuffer textBuffer, boolean autoCloseInput, boolean trimSpaces)
           
 
Method Summary
protected  void _closeInput()
           
protected static String _getCharDesc(int ch)
           
protected  void _handleLF()
           
protected  int _nextChar()
           
protected  String _nextQuotedString()
           
protected  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(String msg)
           
protected  int _skipLeadingSpace()
           
protected  char _unescape()
           
 com.fasterxml.jackson.core.json.JsonReadContext childArrayContext(com.fasterxml.jackson.core.json.JsonReadContext context)
           
 com.fasterxml.jackson.core.json.JsonReadContext childObjectContext(com.fasterxml.jackson.core.json.JsonReadContext context)
           
 void close()
           
protected  com.fasterxml.jackson.core.JsonParseException constructError(String msg, Throwable t)
           
protected  void convertNumberToBigDecimal()
           
protected  void convertNumberToBigInteger()
           
protected  void convertNumberToDouble()
           
protected  void convertNumberToInt()
           
protected  void convertNumberToLong()
           
 BigInteger getBigIntegerValue()
           
 com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
           
 BigDecimal getDecimalValue()
           
 double getDoubleValue()
           
 float getFloatValue()
           
 Object getInputSource()
           
 int getIntValue()
           
 long getLongValue()
           
 com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()
           
 Number getNumberValue()
           
 String getText()
           
protected  long getTokenCharacterOffset()
           
protected  int getTokenColumnNr()
           
protected  int getTokenLineNr()
           
 com.fasterxml.jackson.core.JsonLocation getTokenLocation()
           
 boolean hasMoreInput()
          Method that can be called to see if there is at least one more character to be parsed.
 boolean isClosed()
           
protected  boolean loadMore()
           
 com.fasterxml.jackson.core.JsonToken nextNumber()
           
 com.fasterxml.jackson.core.JsonToken nextNumberOrString()
           
 String 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.
 com.fasterxml.jackson.core.JsonToken nextStringOrLiteral()
           
 int releaseBuffered(Writer out)
           
protected  void releaseBuffers()
           
protected  void reportInvalidNumber(String msg)
           
protected  void reportOverflowInt()
           
protected  void reportOverflowLong()
           
protected  void reportUnexpectedNumberChar(int ch, String comment)
           
 void setSchema(CsvSchema schema)
           
 boolean skipLine()
           
 boolean startNewLine()
          Method called to handle details of starting a new line, which may include skipping a linefeed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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


_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 BigInteger _numberBigInt

_numberBigDecimal

protected BigDecimal _numberBigDecimal

_numberNegative

protected boolean _numberNegative
Flag that indicates whether numeric value has a negative value. That is, whether its textual representation starts with minus character.


_intLength

protected int _intLength
Length of integer part of the number, in characters


_fractLength

protected int _fractLength
Length of the fractional part (not including decimal point or exponent), in characters. Not used for pure integer values.


_expLength

protected int _expLength
Length of the exponent part of the number, if any, not including 'e' marker or sign, just digits. Not used for pure integer values.

Constructor Detail

CsvReader

public CsvReader(CsvParser owner,
                 com.fasterxml.jackson.core.io.IOContext ctxt,
                 Reader r,
                 CsvSchema schema,
                 TextBuffer textBuffer,
                 boolean autoCloseInput,
                 boolean trimSpaces)
Method Detail

setSchema

public void setSchema(CsvSchema schema)

getInputSource

public Object getInputSource()

isClosed

public boolean isClosed()

close

public void close()
           throws IOException
Throws:
IOException

releaseBuffered

public int releaseBuffered(Writer out)
                    throws IOException
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()

getTokenCharacterOffset

protected final long getTokenCharacterOffset()

getTokenLineNr

protected final int getTokenLineNr()

getTokenColumnNr

protected final int getTokenColumnNr()

releaseBuffers

protected void releaseBuffers()
                       throws IOException
Throws:
IOException

_closeInput

protected void _closeInput()
                    throws IOException
Throws:
IOException

loadMore

protected final boolean loadMore()
                          throws IOException
Throws:
IOException

getText

public String getText()

hasMoreInput

public boolean hasMoreInput()
                     throws IOException,
                            com.fasterxml.jackson.core.JsonParseException
Method that can be called to see if there is at least one more character to be parsed.

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

startNewLine

public boolean startNewLine()
                     throws IOException,
                            com.fasterxml.jackson.core.JsonParseException
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
com.fasterxml.jackson.core.JsonParseException

skipLine

public boolean skipLine()
                 throws IOException,
                        com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

nextString

public String nextString()
                  throws IOException,
                         com.fasterxml.jackson.core.JsonParseException
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
com.fasterxml.jackson.core.JsonParseException

nextStringOrLiteral

public com.fasterxml.jackson.core.JsonToken nextStringOrLiteral()
                                                         throws IOException,
                                                                com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

nextNumber

public com.fasterxml.jackson.core.JsonToken nextNumber()
                                                throws IOException,
                                                       com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

nextNumberOrString

public com.fasterxml.jackson.core.JsonToken nextNumberOrString()
                                                        throws IOException,
                                                               com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_nextUnquotedString

protected String _nextUnquotedString(char[] outBuf,
                                     int outPtr)
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_nextQuotedString

protected String _nextQuotedString()
                            throws IOException,
                                   com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_handleLF

protected final void _handleLF()
                        throws IOException,
                               com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_unescape

protected char _unescape()
                  throws IOException,
                         com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_nextChar

protected int _nextChar()
                 throws IOException,
                        com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_skipLeadingSpace

protected int _skipLeadingSpace()
                         throws IOException,
                                com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getNumberValue

public Number getNumberValue()
                      throws IOException,
                             com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getNumberType

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

getIntValue

public int getIntValue()
                throws IOException,
                       com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getLongValue

public long getLongValue()
                  throws IOException,
                         com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getBigIntegerValue

public BigInteger getBigIntegerValue()
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getFloatValue

public float getFloatValue()
                    throws IOException,
                           com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getDoubleValue

public double getDoubleValue()
                      throws IOException,
                             com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

getDecimalValue

public BigDecimal getDecimalValue()
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

_parseNumericValue

protected void _parseNumericValue(int expType)
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonParseException
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:
expType - Numeric type that we will immediately need, if any; mostly necessary to optimize handling of floating point numbers
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

convertNumberToInt

protected void convertNumberToInt()
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

convertNumberToLong

protected void convertNumberToLong()
                            throws IOException,
                                   com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

convertNumberToBigInteger

protected void convertNumberToBigInteger()
                                  throws IOException,
                                         com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

convertNumberToDouble

protected void convertNumberToDouble()
                              throws IOException,
                                     com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

convertNumberToBigDecimal

protected void convertNumberToBigDecimal()
                                  throws IOException,
                                         com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

reportUnexpectedNumberChar

protected void reportUnexpectedNumberChar(int ch,
                                          String comment)
                                   throws com.fasterxml.jackson.core.JsonParseException
Throws:
com.fasterxml.jackson.core.JsonParseException

reportInvalidNumber

protected void reportInvalidNumber(String msg)
                            throws com.fasterxml.jackson.core.JsonParseException
Throws:
com.fasterxml.jackson.core.JsonParseException

reportOverflowInt

protected void reportOverflowInt()
                          throws IOException,
                                 com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

reportOverflowLong

protected void reportOverflowLong()
                           throws IOException,
                                  com.fasterxml.jackson.core.JsonParseException
Throws:
IOException
com.fasterxml.jackson.core.JsonParseException

constructError

protected final com.fasterxml.jackson.core.JsonParseException constructError(String msg,
                                                                             Throwable t)

_getCharDesc

protected static final String _getCharDesc(int ch)

_reportError

protected final void _reportError(String msg)
                           throws com.fasterxml.jackson.core.JsonParseException
Throws:
com.fasterxml.jackson.core.JsonParseException


Copyright © 2012 fasterxml.com. All Rights Reserved.