Package com.api.json

Class JSONStreamTokenizer


  • public class JSONStreamTokenizer
    extends Object
    This class provides similar services to StreamTokenizer but 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void eolIsSignificant​(boolean flag)
      Sets reporting when end of line is detected
      int nextToken​(Integer[] location)
      Discovers the next token in the reader and returns its type (ttype).
      void ordinaryChar​(int ch)
      Sets the supplied character as ordinary in the character lookup table
      void ordinaryChars​(int low, int hi)
      Sets the range of characters supplied (including the endpoints) as ordinary in the character lookup table
      void parseNumbers()
      Initializes the character lookup table for known digits for numeric characters, along with the decimal point and minus sign.
      void pushBack()
      Flags that a character has been returned after completing reading the next token.
      void quoteChar​(int ch)
      Sets the supplied character as a quote delimiter for quoted word identification in the character lookup table
      void resetSyntax()
      Resets the character lookup table with single byte characters as ordinary, and double byte characters as parts of words.
      String toString()
      Convenience method to see the state of the next token and its type (e.g., while debugging)
      void whitespaceChars​(int low, int hi)
      Sets the range of characters as whitespace in the character lookup table
      void wordChars​(int low, int hi)
      Flags the supplied range of characters as word characters in the lookup table.
    • Constructor Detail

      • JSONStreamTokenizer

        public JSONStreamTokenizer​(Reader r)
        Constructs the JST from a Reader. There is no constructor for an InputStream because it can be made into a reader. The same is true for a String.
        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 character
        hi - 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 IOException
        Flags 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:
        toString in class Object
        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 characters
        hi - 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 characters
        hi - ending, higher character range of word characters