public class JsonElementStream
extends java.lang.Object
A stream of JSON JsonElement
.
Modifier and Type | Method and Description |
---|---|
JsonArray |
beginArray()
Return (nullable) A new JSON array, after consuming the '[' token.
|
JsonObject |
beginObject()
Return (nullable) A new JSON object, after consuming the '{' token.
|
JsonElementStream |
decompress()
Enable decompression, where the document may contain an outermost object whose first field has name "$" and whose value is a compression dictionary expressed as an array of strings.
|
void |
endArray()
Expect the next token to be a ']' (end of array), and consume the token.
|
void |
endObject()
Expect the next token to be a '}' (end of object), and consume the token.
|
JsonBooleanToken |
expectBoolean()
Return the next token.
|
void |
expectColon()
Expect the next token to be a colon, and consume the token.
|
void |
expectComma()
Expect the next token to be a comma, and consume the token.
|
JsonNumberToken |
expectNumber()
Return the next token.
|
JsonStringToken |
expectString()
Return the next token.
|
static JsonElementStream |
fromStream(CharStream stream)
|
static JsonElementStream |
fromStream(CharStream stream,
boolean optimized)
Return a new content stream taking input from
stream . |
static JsonElementStream |
fromString(java.lang.String text)
|
static JsonElementStream |
fromString(java.lang.String text,
boolean optimized)
Return a new content stream taking input from
text . |
static JsonElementStream |
fromTokens(JsonTokenStream tokens)
|
static JsonElementStream |
fromTokens(JsonTokenStream tokens,
boolean optimized)
Return a new content stream taking input from
tokens . |
boolean |
isEndArray()
Return
true if the next token indicates the the end of an array (']'). |
boolean |
isEndObject()
Return
true if the next token indicates the the end of an object ('}'). |
boolean |
lookingAt(int type)
Return
true if the next token has the specfied type. |
JsonArray |
readArray()
Return the next JSON array read from the stream.
|
JsonElement |
readElement()
Return (nullable) The next JSON value (null, boolean, number, string, array, object) read from the stream.
|
JsonObject |
readObject()
Return the next JSON object read from the stream.
|
java.lang.String |
readString()
Return the next JSON string read from the stream.
|
public JsonArray beginArray()
Return (nullable) A new JSON array, after consuming the '[' token. Or return null
if the next token is not the start of an array.
null
if the next token is not the start of an array.public JsonObject beginObject()
Return (nullable) A new JSON object, after consuming the '{' token. Or return null
if the next token is not the start of an object.
null
if the next token is not the start of an object.public JsonElementStream decompress()
Enable decompression, where the document may contain an outermost object whose first field has name "$" and whose value is a compression dictionary expressed as an array of strings.
Elsewhere in the document, a field name "$N"
(where N is an integer >= 0) will be treated as a shorthand for the correponding name in the compression dictionary.
Example:
{"$": "ABC", "XYZ", "value": {"$0": 123}, {"$1": 789}}
is decompressed as {"value": {"ABC": 123}, {"XYZ": 789}}
public void endArray()
Expect the next token to be a ']' (end of array), and consume the token.
public void endObject()
Expect the next token to be a '}' (end of object), and consume the token.
public JsonBooleanToken expectBoolean()
Return the next token. Expect the next token to be a boolean value, and consume the token.
public void expectColon()
Expect the next token to be a colon, and consume the token.
public void expectComma()
Expect the next token to be a comma, and consume the token.
public JsonNumberToken expectNumber()
Return the next token. Expect the next token to be a number value, and consume the token.
public JsonStringToken expectString()
Return the next token. Expect the next token to be a string value, and consume the token.
public static JsonElementStream fromStream(CharStream stream)
stream
- Stream parameter.public static JsonElementStream fromStream(CharStream stream, boolean optimized)
Return a new content stream taking input from stream
.
stream
- Input stream.optimized
- See JsonElement.parseOptimized
.stream
.public static JsonElementStream fromString(java.lang.String text)
text
- Text parameter.public static JsonElementStream fromString(java.lang.String text, boolean optimized)
Return a new content stream taking input from text
.
text
- Input text.optimized
- See JsonElement.parseOptimized
.text
.public static JsonElementStream fromTokens(JsonTokenStream tokens)
tokens
- Tokens parameter.public static JsonElementStream fromTokens(JsonTokenStream tokens, boolean optimized)
Return a new content stream taking input from tokens
.
tokens
- Input tokens.optimized
- See JsonElement.parseOptimized
.tokens
.public boolean isEndArray()
Return true
if the next token indicates the the end of an array (']').
true
if the next token indicates the the end of an array (']').public boolean isEndObject()
Return true
if the next token indicates the the end of an object ('}').
true
if the next token indicates the the end of an object ('}').public boolean lookingAt(int type)
Return true
if the next token has the specfied type.
type
- Token type.public JsonArray readArray()
Return the next JSON array read from the stream.
public JsonElement readElement()
Return (nullable) The next JSON value (null, boolean, number, string, array, object) read from the stream.
public JsonObject readObject()
Return the next JSON object read from the stream.
public java.lang.String readString()
Return the next JSON string read from the stream.