public class RecordParser extends Object implements ReadStream<Buffer>, Handler<Buffer>
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:\nThen the output would be:
buffer1:HELLO buffer2:HOW ARE YOU? buffer3:I AM DOING OKInstances 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 RX-ified interface using Vert.x codegen.Modifier and Type | Field and Description |
---|---|
static io.vertx.lang.rx.TypeArg<RecordParser> |
__TYPE_ARG |
Constructor and Description |
---|
RecordParser(Object delegate) |
RecordParser(RecordParser delegate) |
Modifier and Type | Method and Description |
---|---|
void |
delimitedMode(Buffer delim)
Flip the parser into delimited mode, and where the delimiter can be represented
by the delimiter
delim . |
void |
delimitedMode(String delim)
Flip the parser into delimited mode, and where the delimiter can be represented
by the String
delim encoded in latin-1 . |
RecordParser |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
boolean |
equals(Object o) |
RecordParser |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
RecordParser |
fetch(long amount)
Fetch the specified
amount of elements. |
void |
fixedSizeMode(int size)
Flip the parser into fixed size mode, where the record size is specified by
size in bytes. |
RecordParser |
getDelegate() |
void |
handle(Buffer buffer)
This method is called to provide the parser with data.
|
RecordParser |
handler(Handler<Buffer> handler)
Set a data handler.
|
int |
hashCode() |
RecordParser |
maxRecordSize(int size)
Set the maximum allowed size for a record when using the delimited mode.
|
static RecordParser |
newDelimited(Buffer delim)
Create a new
RecordParser instance, initially in delimited mode, and where the delimiter can be represented
by the Buffer delim. |
static RecordParser |
newDelimited(Buffer delim,
Handler<Buffer> output)
Like
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>) but set the output that will receive whole records
which have been parsed. |
static RecordParser |
newDelimited(Buffer delim,
Observable<Buffer> stream)
Like
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>) but wraps the stream . |
static RecordParser |
newDelimited(Buffer delim,
ReadStream<Buffer> stream)
Like
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>) but wraps the stream . |
static RecordParser |
newDelimited(String delim)
Create a new
RecordParser instance, initially in delimited mode, and where the delimiter can be represented
by the String delim endcoded in latin-1 . |
static RecordParser |
newDelimited(String delim,
Handler<Buffer> output)
Like
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>) but set the output that will receive whole records
which have been parsed. |
static RecordParser |
newDelimited(String delim,
Observable<Buffer> stream)
Like
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>) but wraps the stream . |
static RecordParser |
newDelimited(String delim,
ReadStream<Buffer> stream)
Like
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>) but wraps the stream . |
static RecordParser |
newFixed(int size)
Create a new
RecordParser instance, initially in fixed size mode, and where the record size is specified
by the size parameter. |
static RecordParser |
newFixed(int size,
Handler<Buffer> output)
Like
newFixed(int) but set the output that will receive whole records
which have been parsed. |
static RecordParser |
newFixed(int size,
Observable<Buffer> stream)
Like
newFixed(int) but wraps the stream . |
static RecordParser |
newFixed(int size,
ReadStream<Buffer> stream)
Like
newFixed(int) but wraps the stream . |
static RecordParser |
newInstance(RecordParser arg) |
RecordParser |
pause()
Pause the
ReadStream , it sets the buffer in fetch mode and clears the actual demand. |
Pipe<Buffer> |
pipe()
Pause this stream and return a to transfer the elements of this stream to a destination .
|
void |
pipeTo(WriteStream<Buffer> dst)
Pipe this
ReadStream to the WriteStream . |
void |
pipeTo(WriteStream<Buffer> dst,
Handler<AsyncResult<Void>> handler)
Pipe this
ReadStream to the WriteStream . |
RecordParser |
resume()
Resume reading, and sets the buffer in
flowing mode. |
Single<Void> |
rxPipeTo(WriteStream<Buffer> dst)
Pipe this
ReadStream to the WriteStream . |
void |
setOutput(Handler<Buffer> output) |
Observable<Buffer> |
toObservable() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
newInstance, newInstance
newInstance
public static final io.vertx.lang.rx.TypeArg<RecordParser> __TYPE_ARG
public RecordParser(RecordParser delegate)
public RecordParser(Object delegate)
public RecordParser getDelegate()
getDelegate
in interface ReadStream<Buffer>
getDelegate
in interface StreamBase
public Observable<Buffer> toObservable()
toObservable
in interface ReadStream<Buffer>
public Pipe<Buffer> pipe()
WriteStream
.pipe
in interface ReadStream<Buffer>
public void pipeTo(WriteStream<Buffer> dst, Handler<AsyncResult<Void>> handler)
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.
pipeTo
in interface ReadStream<Buffer>
dst
- the destination write streamhandler
- public void pipeTo(WriteStream<Buffer> dst)
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.
pipeTo
in interface ReadStream<Buffer>
dst
- the destination write streampublic Single<Void> rxPipeTo(WriteStream<Buffer> dst)
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.
rxPipeTo
in interface ReadStream<Buffer>
dst
- the destination write streampublic static RecordParser newDelimited(String delim, Handler<Buffer> output)
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
but set the output
that will receive whole records
which have been parsed.delim
- the initial delimiter stringoutput
- handler that will receive the outputpublic static RecordParser newDelimited(String delim, ReadStream<Buffer> stream)
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
but wraps the stream
. The stream
handlers will be set/unset
when the handler(io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
is set.
The pause()
/resume()
operations are propagated to the stream
.delim
- the initial delimiter stringstream
- the wrapped streampublic static RecordParser newDelimited(String delim, Observable<Buffer> stream)
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
but wraps the stream
. The stream
handlers will be set/unset
when the handler(io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
is set.
The pause()
/resume()
operations are propagated to the stream
.delim
- the initial delimiter stringstream
- the wrapped streampublic static RecordParser newDelimited(String delim)
RecordParser
instance, initially in delimited mode, and where the delimiter can be represented
by the String
delim endcoded in latin-1 . Don't use this if your String contains other than latin-1 characters.
output
Will receive whole records which have been parsed.
delim
- the initial delimiter stringpublic static RecordParser newDelimited(Buffer delim)
RecordParser
instance, initially in delimited mode, and where the delimiter can be represented
by the Buffer
delim.
delim
- the initial delimiter bufferpublic static RecordParser newDelimited(Buffer delim, Handler<Buffer> output)
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
but set the output
that will receive whole records
which have been parsed.delim
- the initial delimiter bufferoutput
- handler that will receive the outputpublic static RecordParser newDelimited(Buffer delim, ReadStream<Buffer> stream)
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
but wraps the stream
. The stream
handlers will be set/unset
when the handler(io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
is set.
The pause()
/resume()
operations are propagated to the stream
.delim
- the initial delimiter bufferstream
- the wrapped streampublic static RecordParser newDelimited(Buffer delim, Observable<Buffer> stream)
newDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
but wraps the stream
. The stream
handlers will be set/unset
when the handler(io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
is set.
The pause()
/resume()
operations are propagated to the stream
.delim
- the initial delimiter bufferstream
- the wrapped streampublic static RecordParser newFixed(int size)
RecordParser
instance, initially in fixed size mode, and where the record size is specified
by the size
parameter.
output
Will receive whole records which have been parsed.
size
- the initial record sizepublic static RecordParser newFixed(int size, Handler<Buffer> output)
newFixed(int)
but set the output
that will receive whole records
which have been parsed.size
- the initial record sizeoutput
- handler that will receive the outputpublic static RecordParser newFixed(int size, ReadStream<Buffer> stream)
newFixed(int)
but wraps the stream
. The stream
handlers will be set/unset
when the handler(io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
is set.
The pause()
/resume()
operations are propagated to the stream
.size
- the initial record sizestream
- the wrapped streampublic static RecordParser newFixed(int size, Observable<Buffer> stream)
newFixed(int)
but wraps the stream
. The stream
handlers will be set/unset
when the handler(io.vertx.core.Handler<io.vertx.rxjava.core.buffer.Buffer>)
is set.
The pause()
/resume()
operations are propagated to the stream
.size
- the initial record sizestream
- the wrapped streampublic void delimitedMode(String delim)
delim
encoded in latin-1 . Don't use this if your String contains other than latin-1 characters.
This method can be called multiple times with different values of delim while data is being parsed.
delim
- the new delimeterpublic void delimitedMode(Buffer delim)
delim
.
This method can be called multiple times with different values of delim while data is being parsed.
delim
- the new delimiterpublic void fixedSizeMode(int size)
size
in bytes.
This method can be called multiple times with different values of size while data is being parsed.
size
- the new record sizepublic RecordParser maxRecordSize(int size)
If a record is longer than specified, an IllegalStateException
will be thrown.
size
- the maximum record sizepublic void handle(Buffer buffer)
public RecordParser exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface ReadStream<Buffer>
exceptionHandler
in interface StreamBase
handler
- the exception handlerpublic RecordParser handler(Handler<Buffer> handler)
ReadStream
handler
in interface ReadStream<Buffer>
public RecordParser pause()
ReadStream
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
.
pause
in interface ReadStream<Buffer>
public RecordParser fetch(long amount)
ReadStream
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.fetch
in interface ReadStream<Buffer>
public RecordParser resume()
ReadStream
flowing
mode.
If the ReadStream
has been paused, reading will recommence on it.resume
in interface ReadStream<Buffer>
public RecordParser endHandler(Handler<Void> endHandler)
ReadStream
endHandler
in interface ReadStream<Buffer>
public static RecordParser newInstance(RecordParser arg)
Copyright © 2022 Eclipse. All rights reserved.