Class JsonParser

java.lang.Object
io.vertx.mutiny.core.parsetools.JsonParser
All Implemented Interfaces:
MutinyDelegate, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>, ReadStream<io.vertx.core.parsetools.JsonEvent>, StreamBase, Consumer<io.vertx.core.buffer.Buffer>

public class JsonParser extends Object implements ReadStream<io.vertx.core.parsetools.JsonEvent>, Consumer<io.vertx.core.buffer.Buffer>, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>, MutinyDelegate
A parser class which allows to incrementally parse json elements and emit json parse events instead of parsing a json element fully. This parser is convenient for parsing large json structures.

The parser also parses concatenated json streams or line delimited json streams.

The parser can also parse entire object or array when it is convenient, for instance a very large array of small objects can be parsed efficiently by handling array start/end and object events.

Whenever the parser fails to parse or process the stream, the #exceptionHandler(Handler) is called with the cause of the failure and the current handling stops. After such event, the parser should not handle data anymore.

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Julien Viet
See Also:
  • JsonParser
  • Field Details

  • Constructor Details

    • JsonParser

      public JsonParser(io.vertx.core.parsetools.JsonParser delegate)
      Create a new instance of JsonParser delegating to the given (non-null) instance of JsonParser.
    • JsonParser

      public JsonParser(Object delegate)
  • Method Details

    • accept

      public void accept(io.vertx.core.buffer.Buffer item)
      Handle an item. This method is generated from the original method."
      Specified by:
      accept in interface Consumer<io.vertx.core.buffer.Buffer>
    • handle

      public void handle(io.vertx.core.buffer.Buffer item)
      Handle an item. This method is generated from the original method."
      Specified by:
      handle in interface io.vertx.core.Handler<io.vertx.core.buffer.Buffer>
    • getDelegate

      public io.vertx.core.parsetools.JsonParser getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Specified by:
      getDelegate in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Specified by:
      getDelegate in interface StreamBase
      Returns:
      the delegate instance
    • pipeTo

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<io.vertx.core.parsetools.JsonEvent> arg0)
      Pipe this ReadStream to the WriteStream.

      Elements emitted by this stream will be written to the write stream until this stream ends or fails.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Specified by:
      pipeTo in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Parameters:
      dst - the destination write stream
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • io.vertx.core.parsetools.JsonParser#pipeTo(WriteStream)
    • pipeToAndAwait

      public void pipeToAndAwait(WriteStream<io.vertx.core.parsetools.JsonEvent> arg0)
      Pipe this ReadStream to the WriteStream.

      Elements emitted by this stream will be written to the write stream until this stream ends or fails.

      Unlike the bare Vert.x variant, this method returns a Void. This method awaits indefinitely for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).

      Parameters:
      dst - the destination write stream
      See Also:
      • io.vertx.core.parsetools.JsonParser#pipeTo(WriteStream)
    • pipeToAndForget

      public JsonParser pipeToAndForget(WriteStream<io.vertx.core.parsetools.JsonEvent> arg0)
      Pipe this ReadStream to the WriteStream.

      Elements emitted by this stream will be written to the write stream until this stream ends or fails.

      Unlike the bare Vert.x variant, this method ignores the Void result or any failure.

      Parameters:
      dst - the destination write stream
      Returns:
      The current instance to chain operations if needed.
      See Also:
      • io.vertx.core.parsetools.JsonParser#pipeTo(WriteStream)
    • newParser

      public static JsonParser newParser()
      Create a new JsonParser instance.
    • newParser

      public static JsonParser newParser(ReadStream<io.vertx.core.buffer.Buffer> stream)
      Create a new JsonParser instance.
    • newParser

      public static JsonParser newParser(Flow.Publisher<io.vertx.core.buffer.Buffer> stream)
      Create a new JsonParser instance.
    • write

      public JsonParser write(io.vertx.core.buffer.Buffer buffer)
      Handle a Buffer, pretty much like calling Handler.handle(Object).
      Returns:
      a reference to this, so the API can be used fluently
    • end

      public void end()
      End the stream, this must be called after all the json stream has been processed.
    • objectEventMode

      public JsonParser objectEventMode()
      Flip the parser to emit a stream of events for each new json object.
      Returns:
      a reference to this, so the API can be used fluently
    • objectValueMode

      public JsonParser objectValueMode()
      Flip the parser to emit a single value event for each new json object.

      Json object currently streamed won't be affected.
      Returns:
      a reference to this, so the API can be used fluently
    • arrayEventMode

      public JsonParser arrayEventMode()
      Flip the parser to emit a stream of events for each new json array.
      Returns:
      a reference to this, so the API can be used fluently
    • arrayValueMode

      public JsonParser arrayValueMode()
      Flip the parser to emit a single value event for each new json array.

      Json array currently streamed won't be affected.
      Returns:
      a reference to this, so the API can be used fluently
    • pause

      public JsonParser pause()
      Description copied from interface: ReadStream
      Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

      While it's paused, no data will be sent to the data handler.

      Specified by:
      pause in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Returns:
      a reference to this, so the API can be used fluently
    • resume

      public JsonParser resume()
      Description copied from interface: ReadStream
      Resume reading, and sets the buffer in flowing mode.

      If the ReadStream has been paused, reading will recommence on it.

      Specified by:
      resume in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Returns:
      a reference to this, so the API can be used fluently
    • fetch

      public JsonParser fetch(long amount)
      Description copied from interface: ReadStream
      Fetch the specified amount of elements. If the ReadStream has been paused, reading will recommence with the specified amount of items, otherwise the specified amount will be added to the current stream demand.
      Specified by:
      fetch in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Returns:
      a reference to this, so the API can be used fluently
    • endHandler

      public JsonParser endHandler(Runnable endHandler)
      Description copied from interface: ReadStream
      Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.
      Specified by:
      endHandler in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Returns:
      a reference to this, so the API can be used fluently
    • handler

      public JsonParser handler(Consumer<io.vertx.core.parsetools.JsonEvent> handler)
      Description copied from interface: ReadStream
      Set a data handler. As data is read, the handler will be called with the data.
      Specified by:
      handler in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Returns:
      a reference to this, so the API can be used fluently
    • exceptionHandler

      public JsonParser exceptionHandler(Consumer<Throwable> handler)
      Description copied from interface: ReadStream
      Set an exception handler on the read stream.
      Specified by:
      exceptionHandler in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Specified by:
      exceptionHandler in interface StreamBase
      Parameters:
      handler - the exception handler. Can be null.
      Returns:
      a reference to this, so the API can be used fluently
    • pipe

      public Pipe<io.vertx.core.parsetools.JsonEvent> pipe()
      Pause this stream and return a Pipe to transfer the elements of this stream to a destination WriteStream.

      The stream will be resumed when the pipe will be wired to a WriteStream.

      Specified by:
      pipe in interface ReadStream<io.vertx.core.parsetools.JsonEvent>
      Returns:
      a pipe
    • newInstance

      public static JsonParser newInstance(io.vertx.core.parsetools.JsonParser delegate)
      Creates a new instance of the JsonParser.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toMulti

      @CheckReturnValue public io.smallrye.mutiny.Multi<io.vertx.core.parsetools.JsonEvent> toMulti()
    • toBlockingIterable

      public Iterable<io.vertx.core.parsetools.JsonEvent> toBlockingIterable()
    • toBlockingStream

      public Stream<io.vertx.core.parsetools.JsonEvent> toBlockingStream()