Class JsonParser


  • class JsonParser
    extends java.lang.Object
    A streaming parser for JSON text. The parser reports all events to a given handler.
    • Field Detail

      • handler

        private final JsonHandler<java.lang.Object,​java.lang.Object> handler
      • reader

        private java.io.Reader reader
      • buffer

        private char[] buffer
      • bufferOffset

        private int bufferOffset
      • index

        private int index
      • fill

        private int fill
      • line

        private int line
      • lineOffset

        private int lineOffset
      • current

        private int current
      • captureBuffer

        private java.lang.StringBuilder captureBuffer
      • captureStart

        private int captureStart
      • nestingLevel

        private int nestingLevel
    • Constructor Detail

      • JsonParser

        public JsonParser​(JsonHandler<?,​?> handler)
        Creates a new JsonParser with the given handler. The parser will report all parser events to this handler.
        Parameters:
        handler - the handler to process parser events
    • Method Detail

      • parse

        public void parse​(java.lang.String string)
        Parses the given input string. The input must contain a valid JSON value, optionally padded with whitespace.
        Parameters:
        string - the input string, must be valid JSON
        Throws:
        ParseException - if the input is not valid JSON
      • parse

        public void parse​(java.io.Reader reader)
                   throws java.io.IOException
        Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.

        Characters are read in chunks into a default-sized input buffer. Hence, wrapping a reader in an additional BufferedReader likely won't improve reading performance.

        Parameters:
        reader - the reader to read the input from
        Throws:
        java.io.IOException - if an I/O error occurs in the reader
        ParseException - if the input is not valid JSON
      • parse

        public void parse​(java.io.Reader reader,
                          int buffersize)
                   throws java.io.IOException
        Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.

        Characters are read in chunks into an input buffer of the given size. Hence, wrapping a reader in an additional BufferedReader likely won't improve reading performance.

        Parameters:
        reader - the reader to read the input from
        buffersize - the size of the input buffer in chars
        Throws:
        java.io.IOException - if an I/O error occurs in the reader
        ParseException - if the input is not valid JSON
      • readValue

        private void readValue()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readArray

        private void readArray()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readObject

        private void readObject()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readName

        private java.lang.String readName()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readNull

        private void readNull()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readTrue

        private void readTrue()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readFalse

        private void readFalse()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readRequiredChar

        private void readRequiredChar​(char ch)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • readString

        private void readString()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readStringInternal

        private java.lang.String readStringInternal()
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • readEscape

        private void readEscape()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readNumber

        private void readNumber()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readFraction

        private boolean readFraction()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readExponent

        private boolean readExponent()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readChar

        private boolean readChar​(char ch)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readDigit

        private boolean readDigit()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • skipWhiteSpace

        private void skipWhiteSpace()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        private void read()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • startCapture

        private void startCapture()
      • pauseCapture

        private void pauseCapture()
      • endCapture

        private java.lang.String endCapture()
      • expected

        private ParseException expected​(java.lang.String expected)
      • isWhiteSpace

        private boolean isWhiteSpace()
      • isDigit

        private boolean isDigit()
      • isHexDigit

        private boolean isHexDigit()
      • isEndOfText

        private boolean isEndOfText()