JSON
Version 1.0

org.codehaus.jackson.impl
Class ReaderBasedNumericParser

java.lang.Object
  extended by org.codehaus.jackson.JsonParser
      extended by org.codehaus.jackson.impl.ReaderBasedParserBase
          extended by org.codehaus.jackson.impl.ReaderBasedNumericParser
Direct Known Subclasses:
ReaderBasedParser

public abstract class ReaderBasedNumericParser
extends ReaderBasedParserBase

Intermediate class that implements handling of numeric parsing. Separate from the actual parser class just to isolate numeric parsing: would be nice to use aggregation, but unfortunately many parts are hard to implement without direct access to underlying buffers.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.codehaus.jackson.JsonParser
JsonParser.NumberType
 
Field Summary
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  int mExpLength
          Length of the exponent part of the number, if any, not including 'e' marker or sign, just digits.
protected  int mFractLength
          Length of the fractional part (not including decimal point or exponent), in characters.
protected  int mIntLength
          Length of integer part of the number, in characters
protected  BigDecimal mNumberBigDecimal
           
protected  BigInteger mNumberBigInt
           
protected  double mNumberDouble
           
protected  int mNumberInt
           
protected  long mNumberLong
           
protected  boolean mNumberNegative
          Flag that indicates whether numeric value has a negative value.
protected  int mNumTypesValid
          Bitfield that indicates which numeric representations have been calculated for the current type
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
           
 
Fields inherited from class org.codehaus.jackson.impl.ReaderBasedParserBase
mCurrInputProcessed, mCurrInputRow, mCurrInputRowStart, mCurrToken, mInputBuffer, mInputLen, mInputPtr, mIOContext, mReader, mTextBuffer, mTokenInputCol, mTokenInputRow, mTokenInputTotal
 
Constructor Summary
ReaderBasedNumericParser(IOContext pc, Reader r)
           
 
Method Summary
protected  void convertNumberToBigDecimal()
           
protected  void convertNumberToDouble()
           
protected  void convertNumberToInt()
           
protected  void convertNumberToLong()
           
abstract  String getText()
          Method for accessing textual representation of the current event; if no current event (before first call to JsonParser.nextToken(), or after encountering end-of-input), returns null.
protected  JsonToken parseNumberText(int ch)
          Initial parsing method for number values.
protected  void parseNumericValue()
          Method that will parse actual numeric value out of a syntactically valid number value.
protected  void reportInvalidNumber(String msg)
           
protected  void reportOverflowInt()
           
protected  void reportOverflowLong()
           
protected  void reportUnexpectedNumberChar(int ch, String comment)
           
 
Methods inherited from class org.codehaus.jackson.impl.ReaderBasedParserBase
closeReader, getCharDesc, getCurrentLocation, getNextChar, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, loadMore, markLF, markLF, releaseBuffers, reportError, reportInvalidEOF, reportUnexpectedChar, skipCR, skipLF, throwInternal, wrapError
 
Methods inherited from class org.codehaus.jackson.JsonParser
close, getCurrentName, getCurrentToken, getDecimalValue, getDoubleValue, getIntValue, getLongValue, getNumberType, getNumberValue, getParsingContext, getTextCharacters, getTextLength, getTextOffset, getTokenLocation, hasCurrentToken, nextToken
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

mNumTypesValid

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


mNumberInt

protected int mNumberInt

mNumberLong

protected long mNumberLong

mNumberDouble

protected double mNumberDouble

mNumberBigInt

protected BigInteger mNumberBigInt

mNumberBigDecimal

protected BigDecimal mNumberBigDecimal

mNumberNegative

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


mIntLength

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


mFractLength

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


mExpLength

protected int mExpLength
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

ReaderBasedNumericParser

public ReaderBasedNumericParser(IOContext pc,
                                Reader r)
Method Detail

getText

public abstract String getText()
                        throws IOException,
                               JsonParseException
Description copied from class: JsonParser
Method for accessing textual representation of the current event; if no current event (before first call to JsonParser.nextToken(), or after encountering end-of-input), returns null. Method can be called for any event.

Specified by:
getText in class JsonParser
Throws:
IOException
JsonParseException

parseNumberText

protected final JsonToken parseNumberText(int ch)
                                   throws IOException,
                                          JsonParseException
Initial parsing method for number values. It needs to be able to parse enough input to be able to determine whether the value is to be considered a simple integer value, or a more generic decimal value: latter of which needs to be expressed as a floating point number. The basic rule is that if the number has no fractional or exponential part, it is an integer; otherwise a floating point number.

Because much of input has to be processed in any case, no partial parsing is done: all input text will be stored for further processing. However, actual numeric value conversion will be deferred, since it is usually the most complicated and costliest part of processing.

Throws:
IOException
JsonParseException

parseNumericValue

protected final void parseNumericValue()
                                throws 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.

Throws:
JsonParseException

convertNumberToInt

protected void convertNumberToInt()
                           throws IOException,
                                  JsonParseException
Throws:
IOException
JsonParseException

convertNumberToLong

protected void convertNumberToLong()
                            throws IOException,
                                   JsonParseException
Throws:
IOException
JsonParseException

convertNumberToDouble

protected void convertNumberToDouble()
                              throws IOException,
                                     JsonParseException
Throws:
IOException
JsonParseException

convertNumberToBigDecimal

protected void convertNumberToBigDecimal()
                                  throws IOException,
                                         JsonParseException
Throws:
IOException
JsonParseException

reportUnexpectedNumberChar

protected void reportUnexpectedNumberChar(int ch,
                                          String comment)
                                   throws JsonParseException
Throws:
JsonParseException

reportInvalidNumber

protected void reportInvalidNumber(String msg)
                            throws JsonParseException
Throws:
JsonParseException

reportOverflowInt

protected void reportOverflowInt()
                          throws IOException,
                                 JsonParseException
Throws:
IOException
JsonParseException

reportOverflowLong

protected void reportOverflowLong()
                           throws IOException,
                                  JsonParseException
Throws:
IOException
JsonParseException

JSON
Version 1.0

Apache License, Version 2.0