JSON
Version 1.0

org.codehaus.jackson.impl
Class ReaderBasedParser

java.lang.Object
  extended by org.codehaus.jackson.JsonParser
      extended by org.codehaus.jackson.impl.ReaderBasedParserBase
          extended by org.codehaus.jackson.impl.ReaderBasedNumericParser
              extended by org.codehaus.jackson.impl.ReaderBasedParser

public final class ReaderBasedParser
extends ReaderBasedNumericParser

This is a concrete implementation of JsonParser, which is based on a Reader to handle low-level character conversion tasks.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.codehaus.jackson.JsonParser
JsonParser.NumberType
 
Field Summary
protected  boolean mExpectSeparator
          Flag set when a separator or closing marker for the context is expected.
protected  boolean mFieldInBuffer
          Flag set to indicate whether field name parsed is available from the text buffer or not.
protected  JsonReadContext mParsingContext
           
protected  SymbolTable mSymbols
           
protected  boolean mTokenIncomplete
          Flag that indicates that the current token has not yet been fully processed, and needs to be finished for some access (or skipped to obtain the next token)
 
Fields inherited from class org.codehaus.jackson.impl.ReaderBasedNumericParser
CHAR_NULL, INT_0, INT_1, INT_2, INT_3, INT_4, INT_5, INT_6, INT_7, INT_8, INT_9, INT_DECIMAL_POINT, INT_e, INT_E, INT_MINUS, INT_PLUS, mExpLength, mFractLength, mIntLength, mNumberBigDecimal, mNumberBigInt, mNumberDouble, mNumberInt, mNumberLong, mNumberNegative, mNumTypesValid, NR_BIGDECIMAL, NR_BIGINT, NR_DOUBLE, NR_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
ReaderBasedParser(IOContext ioCtxt, Reader r, SymbolTable st)
           
 
Method Summary
 void close()
           
protected  char decodeEscaped()
           
protected  void finishString()
           
protected  void finishToken()
          Method called to finish parsing of a partially parsed token, in order to access information regarding it.
 JsonLocation getCurrentLocation()
          Method that returns location of the last processed character; usually for error reporting purposes
 String getCurrentName()
          Method that can be called to get the name associated with the current event.
 JsonToken getCurrentToken()
           
 BigDecimal getDecimalValue()
           
 double getDoubleValue()
           
 int getIntValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java int primitive type.
 long getLongValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type.
 JsonParser.NumberType getNumberType()
          If current event is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of type constants; otherwise returns null.
 Number getNumberValue()
          Generic number value accessor method that will work for all kinds of numeric values.
 JsonReadContext getParsingContext()
          Method that can be used to access current parsing context reader is in.
 String getText()
          Method for accessing textual representation of the current event; if no current event (before first call to nextToken(), or after encountering end-of-input), returns null.
 char[] getTextCharacters()
           
 int getTextLength()
           
 int getTextOffset()
           
 JsonLocation getTokenLocation()
          Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.
protected  void handleEOF()
          Method called when an EOF is encountered between tokens.
protected  JsonToken handleFieldName(int i)
           
 boolean hasCurrentToken()
           
protected  JsonToken matchToken(JsonToken token)
           
 JsonToken nextToken()
           
protected  void reportMismatchedEndMarker(int actCh, char expCh)
           
protected  void skipPartial()
          Method called to process and skip remaining contents of a partially read token.
protected  void skipString()
          Method called to skim through rest of unparsed String value, if it is not needed.
protected  JsonToken startString()
           
protected  void throwInvalidSpace(int i)
           
protected  void throwUnquotedSpace(int i, String ctxtDesc)
           
 
Methods inherited from class org.codehaus.jackson.impl.ReaderBasedNumericParser
convertNumberToBigDecimal, convertNumberToDouble, convertNumberToInt, convertNumberToLong, parseNumberText, parseNumericValue, reportInvalidNumber, reportOverflowInt, reportOverflowLong, reportUnexpectedNumberChar
 
Methods inherited from class org.codehaus.jackson.impl.ReaderBasedParserBase
closeReader, getCharDesc, getNextChar, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, loadMore, markLF, markLF, releaseBuffers, reportError, reportInvalidEOF, reportUnexpectedChar, skipCR, skipLF, throwInternal, wrapError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mSymbols

protected final SymbolTable mSymbols

mParsingContext

protected JsonReadContext mParsingContext

mTokenIncomplete

protected boolean mTokenIncomplete
Flag that indicates that the current token has not yet been fully processed, and needs to be finished for some access (or skipped to obtain the next token)


mExpectSeparator

protected boolean mExpectSeparator
Flag set when a separator or closing marker for the context is expected.


mFieldInBuffer

protected boolean mFieldInBuffer
Flag set to indicate whether field name parsed is available from the text buffer or not.

Constructor Detail

ReaderBasedParser

public ReaderBasedParser(IOContext ioCtxt,
                         Reader r,
                         SymbolTable st)
Method Detail

nextToken

public JsonToken nextToken()
                    throws IOException,
                           JsonParseException
Specified by:
nextToken in class JsonParser
Returns:
Next token from the stream, if any found, or null to indicate end-of-input
Throws:
IOException
JsonParseException

getCurrentToken

public JsonToken getCurrentToken()
Specified by:
getCurrentToken in class JsonParser
Returns:
Type of the token this parser currently points to, if any: null both before any tokens have been read, and after end-of-input has been encountered.

hasCurrentToken

public boolean hasCurrentToken()
Specified by:
hasCurrentToken in class JsonParser

getCurrentName

public String getCurrentName()
                      throws IOException,
                             JsonParseException
Method that can be called to get the name associated with the current event. Will return null for all token types except for JsonToken.FIELD_NAME.

Specified by:
getCurrentName in class JsonParser
Throws:
IOException
JsonParseException

close

public void close()
           throws IOException
Specified by:
close in class JsonParser
Throws:
IOException

getParsingContext

public JsonReadContext getParsingContext()
Method that can be used to access current parsing context reader is in. There are 3 different types: root, array and object contexts, with slightly different available information. Contexts are hierarchically nested, and can be used for example for figuring out part of the input document that correspond to specific array or object (for highlighting purposes, or error reporting). Contexts can also be used for simple xpath-like matching of input, if so desired.

Specified by:
getParsingContext in class JsonParser

getTokenLocation

public JsonLocation getTokenLocation()
Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.

Specified by:
getTokenLocation in class JsonParser

getCurrentLocation

public JsonLocation getCurrentLocation()
Method that returns location of the last processed character; usually for error reporting purposes

Specified by:
getCurrentLocation in class ReaderBasedParserBase

getText

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

Specified by:
getText in class ReaderBasedNumericParser
Throws:
IOException
JsonParseException

getTextCharacters

public char[] getTextCharacters()
                         throws IOException,
                                JsonParseException
Specified by:
getTextCharacters in class JsonParser
Throws:
IOException
JsonParseException

getTextLength

public int getTextLength()
                  throws IOException,
                         JsonParseException
Specified by:
getTextLength in class JsonParser
Throws:
IOException
JsonParseException

getTextOffset

public int getTextOffset()
                  throws IOException,
                         JsonParseException
Specified by:
getTextOffset in class JsonParser
Throws:
IOException
JsonParseException

getNumberValue

public Number getNumberValue()
                      throws IOException,
                             JsonParseException
Description copied from class: JsonParser
Generic number value accessor method that will work for all kinds of numeric values. It will return the optimal (simplest/smallest possibl) wrapper object that can express the numeric value just parsed.

Specified by:
getNumberValue in class JsonParser
Throws:
IOException
JsonParseException

getNumberType

public JsonParser.NumberType getNumberType()
                                    throws IOException,
                                           JsonParseException
Description copied from class: JsonParser
If current event is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of type constants; otherwise returns null.

Specified by:
getNumberType in class JsonParser
Throws:
IOException
JsonParseException

getIntValue

public int getIntValue()
                throws IOException,
                       JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java int primitive type.

Note: if the token is an integer, but its value falls outside of range of Java int, a JsonParseException will be thrown to indicate numeric overflow/underflow.

Specified by:
getIntValue in class JsonParser
Throws:
IOException
JsonParseException

getLongValue

public long getLongValue()
                  throws IOException,
                         JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type.

Note: if the token is an integer, but its value falls outside of range of Java long, a JsonParseException will be thrown to indicate numeric overflow/underflow.

Specified by:
getLongValue in class JsonParser
Throws:
IOException
JsonParseException

getDoubleValue

public double getDoubleValue()
                      throws IOException,
                             JsonParseException
Specified by:
getDoubleValue in class JsonParser
Throws:
IOException
JsonParseException

getDecimalValue

public BigDecimal getDecimalValue()
                           throws IOException,
                                  JsonParseException
Specified by:
getDecimalValue in class JsonParser
Throws:
IOException
JsonParseException

handleFieldName

protected JsonToken handleFieldName(int i)
                             throws IOException,
                                    JsonParseException
Throws:
IOException
JsonParseException

startString

protected JsonToken startString()
                         throws IOException,
                                JsonParseException
Throws:
IOException
JsonParseException

finishString

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

skipString

protected void skipString()
                   throws IOException,
                          JsonParseException
Method called to skim through rest of unparsed String value, if it is not needed. This can be done bit faster if contents need not be stored for future access.

Throws:
IOException
JsonParseException

matchToken

protected JsonToken matchToken(JsonToken token)
                        throws IOException,
                               JsonParseException
Throws:
IOException
JsonParseException

skipPartial

protected final void skipPartial()
                          throws IOException,
                                 JsonParseException
Method called to process and skip remaining contents of a partially read token.

Throws:
IOException
JsonParseException

finishToken

protected final void finishToken()
                          throws IOException,
                                 JsonParseException
Method called to finish parsing of a partially parsed token, in order to access information regarding it.

Throws:
IOException
JsonParseException

decodeEscaped

protected final char decodeEscaped()
                            throws IOException,
                                   JsonParseException
Throws:
IOException
JsonParseException

handleEOF

protected void handleEOF()
                  throws JsonParseException
Method called when an EOF is encountered between tokens. If so, it may be a legitimate EOF, but only iff there is no open non-root context.

Throws:
JsonParseException

throwInvalidSpace

protected void throwInvalidSpace(int i)
                          throws JsonParseException
Throws:
JsonParseException

throwUnquotedSpace

protected void throwUnquotedSpace(int i,
                                  String ctxtDesc)
                           throws JsonParseException
Throws:
JsonParseException

reportMismatchedEndMarker

protected void reportMismatchedEndMarker(int actCh,
                                         char expCh)
                                  throws JsonParseException
Throws:
JsonParseException

JSON
Version 1.0

Apache License, Version 2.0