Class RecordParser

  • All Implemented Interfaces:
    io.vertx.core.Handler<Buffer>, ReadStream<Buffer>, StreamBase, Consumer<Buffer>

    public class RecordParser
    extends Object
    implements 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.

    • Constructor Detail

      • RecordParser

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

        public RecordParser​(Object delegate)
    • Method Detail

      • hashCode

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

        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 io.vertx.mutiny.core.streams.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 io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream) that ignores the result of the operation.

        This method subscribes on the result of io.vertx.mutiny.core.streams.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 io.vertx.mutiny.core.streams.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
      • 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,
                                                org.reactivestreams.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,
                                                org.reactivestreams.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,
                                            org.reactivestreams.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
      • 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
      • toBlockingStream

        public Stream<Buffer> toBlockingStream()
      • newInstance

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