Class JsonParser

java.lang.Object
com.formdev.flatlaf.json.JsonParser

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

    • MAX_NESTING_LEVEL

      private static final int MAX_NESTING_LEVEL
      See Also:
    • MIN_BUFFER_SIZE

      private static final int MIN_BUFFER_SIZE
      See Also:
    • DEFAULT_BUFFER_SIZE

      private static final int DEFAULT_BUFFER_SIZE
      See Also:
    • handler

      private final JsonHandler<Object,Object> handler
    • reader

      private 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 StringBuilder captureBuffer
    • captureStart

      private int captureStart
    • nestingLevel

      private int nestingLevel
  • Constructor Details

    • 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 Details

    • parse

      public void parse(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(Reader reader) throws 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:
      IOException - if an I/O error occurs in the reader
      ParseException - if the input is not valid JSON
    • parse

      public void parse(Reader reader, int buffersize) throws 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:
      IOException - if an I/O error occurs in the reader
      ParseException - if the input is not valid JSON
    • readValue

      private void readValue() throws IOException
      Throws:
      IOException
    • readArray

      private void readArray() throws IOException
      Throws:
      IOException
    • readObject

      private void readObject() throws IOException
      Throws:
      IOException
    • readName

      private String readName() throws IOException
      Throws:
      IOException
    • readNull

      private void readNull() throws IOException
      Throws:
      IOException
    • readTrue

      private void readTrue() throws IOException
      Throws:
      IOException
    • readFalse

      private void readFalse() throws IOException
      Throws:
      IOException
    • readRequiredChar

      private void readRequiredChar(char ch) throws IOException
      Throws:
      IOException
    • readString

      private void readString() throws IOException
      Throws:
      IOException
    • readStringInternal

      private String readStringInternal() throws IOException
      Throws:
      IOException
    • readEscape

      private void readEscape() throws IOException
      Throws:
      IOException
    • readNumber

      private void readNumber() throws IOException
      Throws:
      IOException
    • readFraction

      private boolean readFraction() throws IOException
      Throws:
      IOException
    • readExponent

      private boolean readExponent() throws IOException
      Throws:
      IOException
    • readChar

      private boolean readChar(char ch) throws IOException
      Throws:
      IOException
    • readDigit

      private boolean readDigit() throws IOException
      Throws:
      IOException
    • skipWhiteSpace

      private void skipWhiteSpace() throws IOException
      Throws:
      IOException
    • read

      private void read() throws IOException
      Throws:
      IOException
    • startCapture

      private void startCapture()
    • pauseCapture

      private void pauseCapture()
    • endCapture

      private String endCapture()
    • getLocation

      Location getLocation()
    • expected

      private ParseException expected(String expected)
    • error

      private ParseException error(String message)
    • isWhiteSpace

      private boolean isWhiteSpace()
    • isDigit

      private boolean isDigit()
    • isHexDigit

      private boolean isHexDigit()
    • isEndOfText

      private boolean isEndOfText()