Class JsonStreamParser
java.lang.Object
com.couchbase.client.core.json.stream.JsonStreamParser
- All Implemented Interfaces:
Closeable
,AutoCloseable
Create an instance with
builder()
. Use the builder to register
JSON pointers and associated callbacks.
Supply the input JSON by calling feed(byte[], int, int)
repeatedly.
When you're done feeding the parser JSON, call endOfInput()
to validate the input was well-formed.
Finally, call close()
to release resources used by the parser.
Not thread safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Builder instances are reusable provided that ALL configuration of the instance occurs before any call toJsonStreamParser.Builder.build()
. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonStreamParser.Builder
builder()
Construct new parser instances using the builder returned by this method.void
close()
Releases resources managed by the parser.void
Should be called after last chunk of data to parse has been fed.void
feed
(byte[] array, int offset, int len) Consumes all readable bytes from the given buffer.void
feed
(ByteBuffer input)
-
Method Details
-
builder
Construct new parser instances using the builder returned by this method. -
feed
public void feed(byte[] array, int offset, int len) Consumes all readable bytes from the given buffer. Searches for values matching the configured JSON pointers and invokes callbacks for any matches.Call this method repeatedly as more input becomes available.
- Throws:
UncheckedIOException
- if malformed JSON is detected in this chunk of inputRuntimeException
- if a value consumer throws an exception
-
feed
-
endOfInput
public void endOfInput()Should be called after last chunk of data to parse has been fed. After calling this method no more data can be fed and parser assumes no more data will be available.- Throws:
UncheckedIOException
- if malformed JSON is detected in this chunk of input.RuntimeException
- if a value consumer throws an exception
-
close
public void close()Releases resources managed by the parser.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-