public final class JsonStreamParser extends Object implements Iterator<JsonElement>
JsonElement
s from the specified reader
asynchronously.
This class is conditionally thread-safe (see Item 70, Effective Java second edition). To properly use this class across multiple threads, you will need to add some external synchronization. For example:
JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'"); JsonElement element; synchronized (parser) { // synchronize on an object shared by threads if (parser.hasNext()) { element = parser.next(); } }
Constructor and Description |
---|
JsonStreamParser(Reader reader) |
JsonStreamParser(String json) |
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Returns true if a
JsonElement is available on the input for consumption |
JsonElement |
next()
Returns the next available
JsonElement on the reader. |
void |
remove()
This optional
Iterator method is not relevant for stream parsing and hence is not
implemented. |
public JsonStreamParser(String json)
json
- The string containing JSON elements concatenated to each other.public JsonStreamParser(Reader reader)
reader
- The data stream containing JSON elements concatenated to each other.public JsonElement next() throws JsonParseException
JsonElement
on the reader. Null if none available.next
in interface Iterator<JsonElement>
JsonElement
on the reader. Null if none available.JsonParseException
- if the incoming stream is malformed JSON.public boolean hasNext()
JsonElement
is available on the input for consumptionhasNext
in interface Iterator<JsonElement>
JsonElement
is available on the input, false otherwisepublic void remove()
Iterator
method is not relevant for stream parsing and hence is not
implemented.remove
in interface Iterator<JsonElement>
Copyright © 2016. All Rights Reserved.