Package com.formdev.flatlaf.json
Class JsonParser
- java.lang.Object
-
- com.formdev.flatlaf.json.JsonParser
-
class JsonParser extends java.lang.Object
A streaming parser for JSON text. The parser reports all events to a given handler.
-
-
Field Summary
Fields Modifier and Type Field Description private char[]
buffer
private int
bufferOffset
private java.lang.StringBuilder
captureBuffer
private int
captureStart
private int
current
private static int
DEFAULT_BUFFER_SIZE
private int
fill
private JsonHandler<java.lang.Object,java.lang.Object>
handler
private int
index
private int
line
private int
lineOffset
private static int
MAX_NESTING_LEVEL
private static int
MIN_BUFFER_SIZE
private int
nestingLevel
private java.io.Reader
reader
-
Constructor Summary
Constructors Constructor Description JsonParser(JsonHandler<?,?> handler)
Creates a new JsonParser with the given handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
endCapture()
private ParseException
error(java.lang.String message)
private ParseException
expected(java.lang.String expected)
(package private) Location
getLocation()
private boolean
isDigit()
private boolean
isEndOfText()
private boolean
isHexDigit()
private boolean
isWhiteSpace()
void
parse(java.io.Reader reader)
Reads the entire input from the given reader and parses it as JSON.void
parse(java.io.Reader reader, int buffersize)
Reads the entire input from the given reader and parses it as JSON.void
parse(java.lang.String string)
Parses the given input string.private void
pauseCapture()
private void
read()
private void
readArray()
private boolean
readChar(char ch)
private boolean
readDigit()
private void
readEscape()
private boolean
readExponent()
private void
readFalse()
private boolean
readFraction()
private java.lang.String
readName()
private void
readNull()
private void
readNumber()
private void
readObject()
private void
readRequiredChar(char ch)
private void
readString()
private java.lang.String
readStringInternal()
private void
readTrue()
private void
readValue()
private void
skipWhiteSpace()
private void
startCapture()
-
-
-
Field Detail
-
MAX_NESTING_LEVEL
private static final int MAX_NESTING_LEVEL
- See Also:
- Constant Field Values
-
MIN_BUFFER_SIZE
private static final int MIN_BUFFER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
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 readerParseException
- 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 frombuffersize
- the size of the input buffer in chars- Throws:
java.io.IOException
- if an I/O error occurs in the readerParseException
- 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()
-
getLocation
Location getLocation()
-
expected
private ParseException expected(java.lang.String expected)
-
error
private ParseException error(java.lang.String message)
-
isWhiteSpace
private boolean isWhiteSpace()
-
isDigit
private boolean isDigit()
-
isHexDigit
private boolean isHexDigit()
-
isEndOfText
private boolean isEndOfText()
-
-