Package com.formdev.flatlaf.json
Class JsonParser
- java.lang.Object
-
- com.formdev.flatlaf.json.JsonParser
-
class JsonParser extends java.lang.ObjectA streaming parser for JSON text. The parser reports all events to a given handler.
-
-
Field Summary
Fields Modifier and Type Field Description private char[]bufferprivate intbufferOffsetprivate java.lang.StringBuildercaptureBufferprivate intcaptureStartprivate intcurrentprivate static intDEFAULT_BUFFER_SIZEprivate intfillprivate JsonHandler<java.lang.Object,java.lang.Object>handlerprivate intindexprivate intlineprivate intlineOffsetprivate static intMAX_NESTING_LEVELprivate static intMIN_BUFFER_SIZEprivate intnestingLevelprivate java.io.Readerreader
-
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.StringendCapture()private ParseExceptionerror(java.lang.String message)private ParseExceptionexpected(java.lang.String expected)(package private) LocationgetLocation()private booleanisDigit()private booleanisEndOfText()private booleanisHexDigit()private booleanisWhiteSpace()voidparse(java.io.Reader reader)Reads the entire input from the given reader and parses it as JSON.voidparse(java.io.Reader reader, int buffersize)Reads the entire input from the given reader and parses it as JSON.voidparse(java.lang.String string)Parses the given input string.private voidpauseCapture()private voidread()private voidreadArray()private booleanreadChar(char ch)private booleanreadDigit()private voidreadEscape()private booleanreadExponent()private voidreadFalse()private booleanreadFraction()private java.lang.StringreadName()private voidreadNull()private voidreadNumber()private voidreadObject()private voidreadRequiredChar(char ch)private voidreadString()private java.lang.StringreadStringInternal()private voidreadTrue()private voidreadValue()private voidskipWhiteSpace()private voidstartCapture()
-
-
-
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.IOExceptionReads 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
BufferedReaderlikely 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.IOExceptionReads 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
BufferedReaderlikely 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()
-
-