Class JsonStreamParser

java.lang.Object
com.couchbase.client.core.json.stream.JsonStreamParser
All Implemented Interfaces:
Closeable, AutoCloseable

public final class JsonStreamParser extends Object implements Closeable
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.

  • Method Details

    • builder

      public static JsonStreamParser.Builder 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 input
      RuntimeException - if a value consumer throws an exception
    • feed

      public void feed(ByteBuffer input)
    • 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 interface AutoCloseable
      Specified by:
      close in interface Closeable