Package com.formdev.flatlaf.json
Class JsonParser
java.lang.Object
com.formdev.flatlaf.json.JsonParser
A streaming parser for JSON text. The parser reports all events to a given handler.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate char[]
private int
private StringBuilder
private int
private int
private static final int
private int
private final JsonHandler
<Object, Object> private int
private int
private int
private static final int
private static final int
private int
private Reader
-
Constructor Summary
ConstructorsConstructorDescriptionJsonParser
(JsonHandler<?, ?> handler) Creates a new JsonParser with the given handler. -
Method Summary
Modifier and TypeMethodDescriptionprivate String
private ParseException
private ParseException
(package private) Location
private boolean
isDigit()
private boolean
private boolean
private boolean
void
Reads the entire input from the given reader and parses it as JSON.void
Reads the entire input from the given reader and parses it as JSON.void
Parses the given input string.private void
private void
read()
private void
private boolean
readChar
(char ch) private boolean
private void
private boolean
private void
private boolean
private String
readName()
private void
readNull()
private void
private void
private void
readRequiredChar
(char ch) private void
private String
private void
readTrue()
private void
private void
private void
-
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
-
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
-
captureStart
private int captureStart -
nestingLevel
private int nestingLevel
-
-
Constructor Details
-
JsonParser
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
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
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 readerParseException
- if the input is not valid JSON
-
parse
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:
IOException
- if an I/O error occurs in the readerParseException
- if the input is not valid JSON
-
readValue
- Throws:
IOException
-
readArray
- Throws:
IOException
-
readObject
- Throws:
IOException
-
readName
- Throws:
IOException
-
readNull
- Throws:
IOException
-
readTrue
- Throws:
IOException
-
readFalse
- Throws:
IOException
-
readRequiredChar
- Throws:
IOException
-
readString
- Throws:
IOException
-
readStringInternal
- Throws:
IOException
-
readEscape
- Throws:
IOException
-
readNumber
- Throws:
IOException
-
readFraction
- Throws:
IOException
-
readExponent
- Throws:
IOException
-
readChar
- Throws:
IOException
-
readDigit
- Throws:
IOException
-
skipWhiteSpace
- Throws:
IOException
-
read
- Throws:
IOException
-
startCapture
private void startCapture() -
pauseCapture
private void pauseCapture() -
endCapture
-
getLocation
Location getLocation() -
expected
-
error
-
isWhiteSpace
private boolean isWhiteSpace() -
isDigit
private boolean isDigit() -
isHexDigit
private boolean isHexDigit() -
isEndOfText
private boolean isEndOfText()
-