Class RecordParser

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

public class RecordParser extends Object implements MutinyDelegate, ReadStream<Buffer>, io.vertx.core.Handler<Buffer>, Consumer<Buffer>
A helper class which allows you to easily parse protocols which are delimited by a sequence of bytes, or fixed size records.

Instances of this class take as input Buffer instances containing raw bytes, and output records.

For example, if I had a simple ASCII text protocol delimited by '\n' and the input was the following:

 buffer1:HELLO\nHOW ARE Y
 buffer2:OU?\nI AM
 buffer3: DOING OK
 buffer4:\n
 
Then the output would be:

 buffer1:HELLO
 buffer2:HOW ARE YOU?
 buffer3:I AM DOING OK
 
Instances of this class can be changed between delimited mode and fixed size record mode on the fly as individual records are read, this allows you to parse protocols where, for example, the first 5 records might all be fixed size (of potentially different sizes), followed by some delimited records, followed by more fixed size records.

Instances of this class can't currently be used for protocols where the text is encoded with something other than a 1-1 byte-char mapping.

Please see the documentation for more information.

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

  • Field Details

  • Constructor Details

    • RecordParser

      public RecordParser(io.vertx.core.parsetools.RecordParser delegate)
    • RecordParser

      public RecordParser(Object delegate)
  • Method Details

    • getDelegate

      public io.vertx.core.parsetools.RecordParser getDelegate()
      Specified by:
      getDelegate in interface MutinyDelegate
      Specified by:
      getDelegate in interface ReadStream<Buffer>
      Specified by:
      getDelegate in interface StreamBase
      Returns:
      the delegate used by this Mutiny object of generated type
    • toString

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

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

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

      public Pipe<Buffer> pipe()
      Specified by:
      pipe in interface ReadStream<Buffer>
      Returns:
      a pipe
    • pipeTo

      @CheckReturnValue public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<Buffer> dst)
      Pipe this ReadStream to the WriteStream.

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

      Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

      Unlike the bare Vert.x variant, this method returns a Uni. Don't forget to subscribe on it to trigger the operation.

      Specified by:
      pipeTo in interface ReadStream<Buffer>
      Parameters:
      dst - the destination write stream
      Returns:
      the uni firing the result of the operation when completed, or a failure if the operation failed.
    • pipeToAndAwait

      public Void pipeToAndAwait(WriteStream<Buffer> dst)
      Blocking variant of ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream).

      This method waits 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).

      Specified by:
      pipeToAndAwait in interface ReadStream<Buffer>
      Parameters:
      dst - the destination write stream
      Returns:
      the Void instance produced by the operation.
    • pipeToAndForget

      public void pipeToAndForget(WriteStream<Buffer> dst)
      Variant of ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream) that ignores the result of the operation.

      This method subscribes on the result of ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream), but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from ReadStream.pipeTo(io.vertx.mutiny.core.streams.WriteStream) but you don't need to compose it with other operations.

      Specified by:
      pipeToAndForget in interface ReadStream<Buffer>
      Parameters:
      dst - the destination write stream
    • setOutput

      public void setOutput(Consumer<Buffer> output)
    • newDelimited

      public static RecordParser newDelimited(String delim, Consumer<Buffer> output)
      Parameters:
      delim - the initial delimiter string
      output - handler that will receive the output
      Returns:
    • newDelimited

      public static RecordParser newDelimited(String delim, ReadStream<Buffer> stream)
      Parameters:
      delim - the initial delimiter string
      stream - the wrapped stream
      Returns:
    • newDelimited

      public static RecordParser newDelimited(String delim, Flow.Publisher<Buffer> stream)
      Parameters:
      delim - the initial delimiter string
      stream - the wrapped stream
      Returns:
    • newDelimited

      public static RecordParser newDelimited(String delim)
      Parameters:
      delim - the initial delimiter string
      Returns:
    • newDelimited

      public static RecordParser newDelimited(Buffer delim)
      Parameters:
      delim - the initial delimiter buffer
      Returns:
    • newDelimited

      public static RecordParser newDelimited(Buffer delim, Consumer<Buffer> output)
      Parameters:
      delim - the initial delimiter buffer
      output - handler that will receive the output
      Returns:
    • newDelimited

      public static RecordParser newDelimited(Buffer delim, ReadStream<Buffer> stream)
      Parameters:
      delim - the initial delimiter buffer
      stream - the wrapped stream
      Returns:
    • newDelimited

      public static RecordParser newDelimited(Buffer delim, Flow.Publisher<Buffer> stream)
      Parameters:
      delim - the initial delimiter buffer
      stream - the wrapped stream
      Returns:
    • newFixed

      public static RecordParser newFixed(int size)
      Parameters:
      size - the initial record size
      Returns:
    • newFixed

      public static RecordParser newFixed(int size, Consumer<Buffer> output)
      Parameters:
      size - the initial record size
      output - handler that will receive the output
      Returns:
    • newFixed

      public static RecordParser newFixed(int size, ReadStream<Buffer> stream)
      Parameters:
      size - the initial record size
      stream - the wrapped stream
      Returns:
    • newFixed

      public static RecordParser newFixed(int size, Flow.Publisher<Buffer> stream)
      Parameters:
      size - the initial record size
      stream - the wrapped stream
      Returns:
    • delimitedMode

      public void delimitedMode(String delim)
      Parameters:
      delim - the new delimeter
    • delimitedMode

      public void delimitedMode(Buffer delim)
      Parameters:
      delim - the new delimiter
    • fixedSizeMode

      public void fixedSizeMode(int size)
      Parameters:
      size - the new record size
    • maxRecordSize

      public RecordParser maxRecordSize(int size)
      Parameters:
      size - the maximum record size
      Returns:
      a reference to this, so the API can be used fluently
    • handle

      public void handle(Buffer buffer)
      Specified by:
      handle in interface io.vertx.core.Handler<Buffer>
      Parameters:
      buffer - a chunk of data
    • exceptionHandler

      public RecordParser exceptionHandler(Consumer<Throwable> handler)
      Specified by:
      exceptionHandler in interface ReadStream<Buffer>
      Specified by:
      exceptionHandler in interface StreamBase
      Parameters:
      handler - the exception handler
      Returns:
    • handler

      public RecordParser handler(Consumer<Buffer> handler)
      Specified by:
      handler in interface ReadStream<Buffer>
      Returns:
    • pause

      public RecordParser pause()
      Specified by:
      pause in interface ReadStream<Buffer>
      Returns:
      a reference to this, so the API can be used fluently
    • fetch

      public RecordParser fetch(long amount)
      Specified by:
      fetch in interface ReadStream<Buffer>
      Returns:
      a reference to this, so the API can be used fluently
    • resume

      public RecordParser resume()
      Specified by:
      resume in interface ReadStream<Buffer>
      Returns:
      a reference to this, so the API can be used fluently
    • endHandler

      public RecordParser endHandler(Runnable endHandler)
      Specified by:
      endHandler in interface ReadStream<Buffer>
      Returns:
    • toMulti

      @CheckReturnValue public io.smallrye.mutiny.Multi<Buffer> toMulti()
      Specified by:
      toMulti in interface ReadStream<Buffer>
    • toBlockingIterable

      public Iterable<Buffer> toBlockingIterable()
    • toBlockingStream

      public Stream<Buffer> toBlockingStream()
    • accept

      public void accept(Buffer item)
      Specified by:
      accept in interface Consumer<Buffer>
    • newInstance

      public static RecordParser newInstance(io.vertx.core.parsetools.RecordParser arg)