Class B2JsonReader


  • public class B2JsonReader
    extends java.lang.Object
    Reads a stream of characters and converts them to JSON tokens.

    This class is NOT thread safe.

    • Constructor Detail

      • B2JsonReader

        public B2JsonReader​(java.io.Reader in)
                     throws java.io.IOException
        Initializes a new reader.
        Throws:
        java.io.IOException
    • Method Detail

      • peekNextNotWhitespaceChar

        public char peekNextNotWhitespaceChar()
                                       throws java.io.IOException,
                                              B2JsonException
        Returns the next char that is not whitespace, but does not consume it.
        Throws:
        java.io.IOException
        B2JsonException
      • skipValue

        public void skipValue()
                       throws java.io.IOException,
                              B2JsonException
        Skips over a value of any type.
        Throws:
        java.io.IOException
        B2JsonException
      • readNumberAsString

        public java.lang.String readNumberAsString()
                                            throws java.io.IOException,
                                                   B2JsonException
        Reads the next value, which is expected to be a number, and returns it as a string. Throws JsonError if the next thing is not a number.
        Throws:
        java.io.IOException
        B2JsonException
      • readString

        public java.lang.String readString()
                                    throws B2JsonException,
                                           java.io.IOException
        Reads a string value, returning its contents.
        Throws:
        B2JsonException
        java.io.IOException
      • startObjectAndCheckForContents

        public boolean startObjectAndCheckForContents()
                                               throws B2JsonException,
                                                      java.io.IOException
        Reads the open brace for an object. Returns true iff the object has any fields. To read an object, use this structure: if (in.startObjectAndCheckForContents()) { do { String fieldName = on.readObjectFieldNameAndColon } while (in.objectHasMoreFields()); } in.finishObject();
        Throws:
        B2JsonException
        java.io.IOException
      • objectHasMoreFields

        public boolean objectHasMoreFields()
                                    throws java.io.IOException,
                                           B2JsonException
        Does the object have any more fields?
        Throws:
        java.io.IOException
        B2JsonException
      • nextNonWhitespaceIsEof

        public boolean nextNonWhitespaceIsEof()
                                       throws java.io.IOException,
                                              B2JsonException
        Is the next character the given char?
        Throws:
        java.io.IOException
        B2JsonException
      • readObjectFieldNameAndColon

        public java.lang.String readObjectFieldNameAndColon()
                                                     throws B2JsonException,
                                                            java.io.IOException
        Reads the name of the next object field. After calling this, you can read the value using whichever method is right for the value type.
        Throws:
        B2JsonException
        java.io.IOException
      • finishObject

        public void finishObject()
                          throws B2JsonException,
                                 java.io.IOException
        Reads the close brace for an object.
        Throws:
        B2JsonException
        java.io.IOException
      • startArrayAndCheckForContents

        public boolean startArrayAndCheckForContents()
                                              throws java.io.IOException,
                                                     B2JsonException
        Starts reading an array by reading the "[". Returns true iff there is anything in the array. Use this code to read an array: if (in.startArrayAndCheckForContents()) { do { // read value } while (in.arrayHasMoreValues()); } finishArray();
        Throws:
        java.io.IOException
        B2JsonException
      • arrayHasMoreValues

        public boolean arrayHasMoreValues()
                                   throws java.io.IOException,
                                          B2JsonException
        Are there more values in an array?
        Throws:
        java.io.IOException
        B2JsonException
      • finishArray

        public void finishArray()
                         throws B2JsonException,
                                java.io.IOException
        Reads the close bracket for an array.
        Throws:
        B2JsonException
        java.io.IOException