Class RecordParser
- java.lang.Object
-
- io.vertx.mutiny.core.parsetools.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 theoriginal
non Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<RecordParser>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description RecordParser(io.vertx.core.parsetools.RecordParser delegate)
RecordParser(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(Buffer item)
void
delimitedMode(Buffer delim)
void
delimitedMode(String delim)
RecordParser
endHandler(Runnable endHandler)
boolean
equals(Object o)
RecordParser
exceptionHandler(Consumer<Throwable> handler)
RecordParser
fetch(long amount)
void
fixedSizeMode(int size)
io.vertx.core.parsetools.RecordParser
getDelegate()
void
handle(Buffer buffer)
RecordParser
handler(Consumer<Buffer> handler)
int
hashCode()
RecordParser
maxRecordSize(int size)
static RecordParser
newDelimited(Buffer delim)
static RecordParser
newDelimited(Buffer delim, ReadStream<Buffer> stream)
static RecordParser
newDelimited(Buffer delim, Consumer<Buffer> output)
static RecordParser
newDelimited(Buffer delim, org.reactivestreams.Publisher<Buffer> stream)
static RecordParser
newDelimited(String delim)
static RecordParser
newDelimited(String delim, ReadStream<Buffer> stream)
static RecordParser
newDelimited(String delim, Consumer<Buffer> output)
static RecordParser
newDelimited(String delim, org.reactivestreams.Publisher<Buffer> stream)
static RecordParser
newFixed(int size)
static RecordParser
newFixed(int size, ReadStream<Buffer> stream)
static RecordParser
newFixed(int size, Consumer<Buffer> output)
static RecordParser
newFixed(int size, org.reactivestreams.Publisher<Buffer> stream)
static RecordParser
newInstance(io.vertx.core.parsetools.RecordParser arg)
RecordParser
pause()
Pipe<Buffer>
pipe()
io.smallrye.mutiny.Uni<Void>
pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStream
to theWriteStream
.Void
pipeToAndAwait(WriteStream<Buffer> dst)
Blocking variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
.) void
pipeToAndForget(WriteStream<Buffer> dst)
Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream
that ignores the result of the operation.) RecordParser
resume()
void
setOutput(Consumer<Buffer> output)
Iterable<Buffer>
toBlockingIterable()
Stream<Buffer>
toBlockingStream()
io.smallrye.mutiny.Multi<Buffer>
toMulti()
String
toString()
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<RecordParser> __TYPE_ARG
-
-
Constructor Detail
-
RecordParser
public RecordParser(io.vertx.core.parsetools.RecordParser delegate)
-
RecordParser
public RecordParser(Object delegate)
-
-
Method Detail
-
getDelegate
public io.vertx.core.parsetools.RecordParser getDelegate()
- Specified by:
getDelegate
in interfaceReadStream<Buffer>
- Specified by:
getDelegate
in interfaceStreamBase
-
pipe
public Pipe<Buffer> pipe()
- Specified by:
pipe
in interfaceReadStream<Buffer>
- Returns:
- a pipe
-
pipeTo
public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStream
to theWriteStream
.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 interfaceReadStream<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 ofio.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 interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream- Returns:
- the Void instance produced by the operation.
-
pipeToAndForget
public void pipeToAndForget(WriteStream<Buffer> dst)
Variant ofio.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 interfaceReadStream<Buffer>
- Parameters:
dst
- the destination write stream
-
newDelimited
public static RecordParser newDelimited(String delim, Consumer<Buffer> output)
- Parameters:
delim
- the initial delimiter stringoutput
- handler that will receive the output- Returns:
-
newDelimited
public static RecordParser newDelimited(String delim, ReadStream<Buffer> stream)
- Parameters:
delim
- the initial delimiter stringstream
- the wrapped stream- Returns:
-
newDelimited
public static RecordParser newDelimited(String delim, org.reactivestreams.Publisher<Buffer> stream)
- Parameters:
delim
- the initial delimiter stringstream
- 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 bufferoutput
- handler that will receive the output- Returns:
-
newDelimited
public static RecordParser newDelimited(Buffer delim, ReadStream<Buffer> stream)
- Parameters:
delim
- the initial delimiter bufferstream
- the wrapped stream- Returns:
-
newDelimited
public static RecordParser newDelimited(Buffer delim, org.reactivestreams.Publisher<Buffer> stream)
- Parameters:
delim
- the initial delimiter bufferstream
- 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 sizeoutput
- handler that will receive the output- Returns:
-
newFixed
public static RecordParser newFixed(int size, ReadStream<Buffer> stream)
- Parameters:
size
- the initial record sizestream
- the wrapped stream- Returns:
-
newFixed
public static RecordParser newFixed(int size, org.reactivestreams.Publisher<Buffer> stream)
- Parameters:
size
- the initial record sizestream
- 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 interfaceio.vertx.core.Handler<Buffer>
- Parameters:
buffer
- a chunk of data
-
exceptionHandler
public RecordParser exceptionHandler(Consumer<Throwable> handler)
- Specified by:
exceptionHandler
in interfaceReadStream<Buffer>
- Specified by:
exceptionHandler
in interfaceStreamBase
- Parameters:
handler
- the exception handler- Returns:
-
handler
public RecordParser handler(Consumer<Buffer> handler)
- Specified by:
handler
in interfaceReadStream<Buffer>
- Returns:
-
pause
public RecordParser pause()
- Specified by:
pause
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
fetch
public RecordParser fetch(long amount)
- Specified by:
fetch
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
resume
public RecordParser resume()
- Specified by:
resume
in interfaceReadStream<Buffer>
- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
public RecordParser endHandler(Runnable endHandler)
- Specified by:
endHandler
in interfaceReadStream<Buffer>
- Returns:
-
toMulti
public io.smallrye.mutiny.Multi<Buffer> toMulti()
- Specified by:
toMulti
in interfaceReadStream<Buffer>
-
newInstance
public static RecordParser newInstance(io.vertx.core.parsetools.RecordParser arg)
-
-