Package com.api.json
Class JSONStreamTokenizer
- java.lang.Object
-
- com.api.json.JSONStreamTokenizer
-
public class JSONStreamTokenizer extends Object
This class provides similar services toStreamTokenizerbut it works on a character by character basis, whereas the StreamTokenizer is based on individual bytes so is not handling solidus nor unicode correctly. This class is solely for parsing JSON content.
-
-
Constructor Summary
Constructors Constructor Description JSONStreamTokenizer(Reader r)Constructs the JST from aReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voideolIsSignificant(boolean flag)Sets reporting when end of line is detectedintnextToken(Integer[] location)Discovers the next token in the reader and returns its type (ttype).voidordinaryChar(int ch)Sets the supplied character as ordinary in the character lookup tablevoidordinaryChars(int low, int hi)Sets the range of characters supplied (including the endpoints) as ordinary in the character lookup tablevoidparseNumbers()Initializes the character lookup table for known digits for numeric characters, along with the decimal point and minus sign.voidpushBack()Flags that a character has been returned after completing reading the next token.voidquoteChar(int ch)Sets the supplied character as a quote delimiter for quoted word identification in the character lookup tablevoidresetSyntax()Resets the character lookup table with single byte characters as ordinary, and double byte characters as parts of words.StringtoString()Convenience method to see the state of the next token and its type (e.g., while debugging)voidwhitespaceChars(int low, int hi)Sets the range of characters as whitespace in the character lookup tablevoidwordChars(int low, int hi)Flags the supplied range of characters as word characters in the lookup table.
-
-
-
Field Detail
-
TT_EOF
public static final int TT_EOF
- See Also:
- Constant Field Values
-
TT_CR
public static final int TT_CR
- See Also:
- Constant Field Values
-
TT_EOL
public static final int TT_EOL
- See Also:
- Constant Field Values
-
TT_NUMBER
public static final int TT_NUMBER
- See Also:
- Constant Field Values
-
TT_WORD
public static final int TT_WORD
- See Also:
- Constant Field Values
-
nval
public double nval
-
sval
public String sval
-
ttype
public int ttype
-
LN_CNTR
public static int LN_CNTR
-
LN_OFFSET
public static int LN_OFFSET
-
-
Constructor Detail
-
JSONStreamTokenizer
public JSONStreamTokenizer(Reader r)
Constructs the JST from aReader. There is no constructor for anInputStreambecause it can be made into a reader. The same is true for aString.- Parameters:
r- the reader to be read containing JSON content.
-
-
Method Detail
-
eolIsSignificant
public void eolIsSignificant(boolean flag)
Sets reporting when end of line is detected- Parameters:
flag- whether or not to report when end of line is detected
-
nextToken
public int nextToken(Integer[] location) throws IOException
Discovers the next token in the reader and returns its type (ttype). If a number is detected, it is returned as a double in the nval. If a word or quoted word is detected, it is returned in the sval.- Parameters:
location- where we are reading from the input stream- Returns:
- the type of next token encountered in the reader
- Throws:
IOException- if unable to read from the reader
-
ordinaryChar
public void ordinaryChar(int ch)
Sets the supplied character as ordinary in the character lookup table- Parameters:
ch- The character to be tested
-
ordinaryChars
public void ordinaryChars(int low, int hi)Sets the range of characters supplied (including the endpoints) as ordinary in the character lookup table- Parameters:
low- starting, lower value characterhi- ending, higher value character
-
parseNumbers
public void parseNumbers()
Initializes the character lookup table for known digits for numeric characters, along with the decimal point and minus sign. TODO: add plus sign?
-
pushBack
public void pushBack() throws IOExceptionFlags that a character has been returned after completing reading the next token.- Throws:
IOException- if unable to read from the reader
-
quoteChar
public void quoteChar(int ch)
Sets the supplied character as a quote delimiter for quoted word identification in the character lookup table- Parameters:
ch- The character defining a quote character
-
resetSyntax
public void resetSyntax()
Resets the character lookup table with single byte characters as ordinary, and double byte characters as parts of words.
-
toString
public String toString()
Convenience method to see the state of the next token and its type (e.g., while debugging)- Overrides:
toStringin classObject- See Also:
Object.toString()
-
whitespaceChars
public void whitespaceChars(int low, int hi)Sets the range of characters as whitespace in the character lookup table- Parameters:
low- starting, lower range of whitespace charactershi- ending, higher range of whitespace characters
-
wordChars
public void wordChars(int low, int hi)Flags the supplied range of characters as word characters in the lookup table. These characters may also be flagged as numeric characters- Parameters:
low- starting, lower character range of word charactershi- ending, higher character range of word characters
-
-