Class RecordParser
- java.lang.Object
-
- io.vertx.reactivex.core.parsetools.RecordParser
-
- All Implemented Interfaces:
Handler<Buffer>,io.vertx.lang.rx.RxDelegate,ReadStream<Buffer>,StreamBase
public class RecordParser extends Object implements io.vertx.lang.rx.RxDelegate, ReadStream<Buffer>, Handler<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
Bufferinstances 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
originalnon RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static io.vertx.lang.rx.TypeArg<RecordParser>__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description RecordParser(RecordParser delegate)RecordParser(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelimitedMode(Buffer delim)Flip the parser into delimited mode, and where the delimiter can be represented by the delimiterdelim.voiddelimitedMode(String delim)Flip the parser into delimited mode, and where the delimiter can be represented by the Stringdelimencoded in latin-1 .RecordParserendHandler(Handler<Void> endHandler)Set an end handler.booleanequals(Object o)RecordParserexceptionHandler(Handler<Throwable> handler)Set an exception handler on the read stream.RecordParserfetch(long amount)Fetch the specifiedamountof elements.voidfixedSizeMode(int size)Flip the parser into fixed size mode, where the record size is specified bysizein bytes.RecordParsergetDelegate()voidhandle(Buffer buffer)This method is called to provide the parser with data.RecordParserhandler(Handler<Buffer> handler)Set a data handler.inthashCode()RecordParsermaxRecordSize(int size)Set the maximum allowed size for a record when using the delimited mode.static RecordParsernewDelimited(Buffer delim)Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by theBufferdelim.static RecordParsernewDelimited(Buffer delim, Flowable<Buffer> stream)LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream.static RecordParsernewDelimited(Buffer delim, Handler<Buffer> output)LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but set theoutputthat will receive whole records which have been parsed.static RecordParsernewDelimited(Buffer delim, ReadStream<Buffer> stream)LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream.static RecordParsernewDelimited(String delim)Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by the Stringdelim endcoded in latin-1 .static RecordParsernewDelimited(String delim, Flowable<Buffer> stream)LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream.static RecordParsernewDelimited(String delim, Handler<Buffer> output)LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but set theoutputthat will receive whole records which have been parsed.static RecordParsernewDelimited(String delim, ReadStream<Buffer> stream)LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream.static RecordParsernewFixed(int size)Create a newRecordParserinstance, initially in fixed size mode, and where the record size is specified by thesizeparameter.static RecordParsernewFixed(int size, Flowable<Buffer> stream)LikenewFixed(int)but wraps thestream.static RecordParsernewFixed(int size, Handler<Buffer> output)LikenewFixed(int)but set theoutputthat will receive whole records which have been parsed.static RecordParsernewFixed(int size, ReadStream<Buffer> stream)LikenewFixed(int)but wraps thestream.static RecordParsernewInstance(RecordParser arg)RecordParserpause()Pause theReadStream, it sets the buffer infetchmode and clears the actual demand.Pipe<Buffer>pipe()Pause this stream and return a to transfer the elements of this stream to a destination .Future<Void>pipeTo(WriteStream<Buffer> dst)Pipe thisReadStreamto theWriteStream.RecordParserresume()Resume reading, and sets the buffer inflowingmode.CompletablerxPipeTo(WriteStream<Buffer> dst)Pipe thisReadStreamto theWriteStream.voidsetOutput(Handler<Buffer> output)Flowable<Buffer>toFlowable()Observable<Buffer>toObservable()StringtoString()
-
-
-
Field Detail
-
__TYPE_ARG
public static final io.vertx.lang.rx.TypeArg<RecordParser> __TYPE_ARG
-
-
Constructor Detail
-
RecordParser
public RecordParser(RecordParser delegate)
-
RecordParser
public RecordParser(Object delegate)
-
-
Method Detail
-
getDelegate
public RecordParser getDelegate()
- Specified by:
getDelegatein interfaceReadStream<Buffer>- Specified by:
getDelegatein interfaceio.vertx.lang.rx.RxDelegate- Specified by:
getDelegatein interfaceStreamBase
-
toObservable
public Observable<Buffer> toObservable()
- Specified by:
toObservablein interfaceReadStream<Buffer>
-
toFlowable
public Flowable<Buffer> toFlowable()
- Specified by:
toFlowablein interfaceReadStream<Buffer>
-
pipe
public Pipe<Buffer> pipe()
Pause this stream and return a to transfer the elements of this stream to a destination . The stream will be resumed when the pipe will be wired to aWriteStream.- Specified by:
pipein interfaceReadStream<Buffer>- Returns:
- a pipe
-
pipeTo
public Future<Void> pipeTo(WriteStream<Buffer> dst)
Pipe thisReadStreamto theWriteStream.Elements emitted by this stream will be written to the write stream until this stream ends or fails.
- Specified by:
pipeToin interfaceReadStream<Buffer>- Parameters:
dst- the destination write stream- Returns:
- a future notified when the write stream will be ended with the outcome
-
rxPipeTo
public Completable rxPipeTo(WriteStream<Buffer> dst)
Pipe thisReadStreamto theWriteStream.Elements emitted by this stream will be written to the write stream until this stream ends or fails.
- Specified by:
rxPipeToin interfaceReadStream<Buffer>- Parameters:
dst- the destination write stream- Returns:
- a future notified when the write stream will be ended with the outcome
-
newDelimited
public static RecordParser newDelimited(String delim, Handler<Buffer> output)
LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but set theoutputthat will receive whole records which have been parsed.- Parameters:
delim- the initial delimiter stringoutput- handler that will receive the output- Returns:
-
newDelimited
public static RecordParser newDelimited(String delim, ReadStream<Buffer> stream)
LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream. Thestreamhandlers will be set/unset when thehandler(io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter stringstream- the wrapped stream- Returns:
-
newDelimited
public static RecordParser newDelimited(String delim, Flowable<Buffer> stream)
LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream. Thestreamhandlers will be set/unset when thehandler(io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter stringstream- the wrapped stream- Returns:
-
newDelimited
public static RecordParser newDelimited(String delim)
Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by the Stringdelim endcoded in latin-1 . Don't use this if your String contains other than latin-1 characters.outputWill receive whole records which have been parsed.- Parameters:
delim- the initial delimiter string- Returns:
-
newDelimited
public static RecordParser newDelimited(Buffer delim)
Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by theBufferdelim.- Parameters:
delim- the initial delimiter buffer- Returns:
-
newDelimited
public static RecordParser newDelimited(Buffer delim, Handler<Buffer> output)
LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but set theoutputthat will receive whole records which have been parsed.- Parameters:
delim- the initial delimiter bufferoutput- handler that will receive the output- Returns:
-
newDelimited
public static RecordParser newDelimited(Buffer delim, ReadStream<Buffer> stream)
LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream. Thestreamhandlers will be set/unset when thehandler(io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter bufferstream- the wrapped stream- Returns:
-
newDelimited
public static RecordParser newDelimited(Buffer delim, Flowable<Buffer> stream)
LikenewDelimited(java.lang.String, io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)but wraps thestream. Thestreamhandlers will be set/unset when thehandler(io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter bufferstream- the wrapped stream- Returns:
-
newFixed
public static RecordParser newFixed(int size)
Create a newRecordParserinstance, initially in fixed size mode, and where the record size is specified by thesizeparameter.outputWill receive whole records which have been parsed.- Parameters:
size- the initial record size- Returns:
-
newFixed
public static RecordParser newFixed(int size, Handler<Buffer> output)
LikenewFixed(int)but set theoutputthat will receive whole records which have been parsed.- Parameters:
size- the initial record sizeoutput- handler that will receive the output- Returns:
-
newFixed
public static RecordParser newFixed(int size, ReadStream<Buffer> stream)
LikenewFixed(int)but wraps thestream. Thestreamhandlers will be set/unset when thehandler(io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
size- the initial record sizestream- the wrapped stream- Returns:
-
newFixed
public static RecordParser newFixed(int size, Flowable<Buffer> stream)
LikenewFixed(int)but wraps thestream. Thestreamhandlers will be set/unset when thehandler(io.vertx.core.Handler<io.vertx.core.buffer.Buffer>)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
size- the initial record sizestream- the wrapped stream- Returns:
-
delimitedMode
public void delimitedMode(String delim)
Flip the parser into delimited mode, and where the delimiter can be represented by the Stringdelimencoded 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.
- Parameters:
delim- the new delimeter
-
delimitedMode
public void delimitedMode(Buffer delim)
Flip the parser into delimited mode, and where the delimiter can be represented by the delimiterdelim.This method can be called multiple times with different values of delim while data is being parsed.
- Parameters:
delim- the new delimiter
-
fixedSizeMode
public void fixedSizeMode(int size)
Flip the parser into fixed size mode, where the record size is specified bysizein bytes.This method can be called multiple times with different values of size while data is being parsed.
- Parameters:
size- the new record size
-
maxRecordSize
public RecordParser maxRecordSize(int size)
Set the maximum allowed size for a record when using the delimited mode. The delimiter itself does not count for the record size.If a record is longer than specified, an
IllegalStateExceptionwill be thrown.- Parameters:
size- the maximum record size- Returns:
- a reference to this, so the API can be used fluently
-
handle
public void handle(Buffer buffer)
This method is called to provide the parser with data.
-
exceptionHandler
public RecordParser exceptionHandler(Handler<Throwable> handler)
Description copied from interface:ReadStreamSet an exception handler on the read stream.- Specified by:
exceptionHandlerin interfaceReadStream<Buffer>- Specified by:
exceptionHandlerin interfaceStreamBase- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
handler
public RecordParser handler(Handler<Buffer> handler)
Description copied from interface:ReadStreamSet a data handler. As data is read, the handler will be called with the data.- Specified by:
handlerin interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
pause
public RecordParser pause()
Description copied from interface:ReadStreamPause theReadStream, it sets the buffer infetchmode and clears the actual demand.While it's paused, no data will be sent to the data
handler.- Specified by:
pausein interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
fetch
public RecordParser fetch(long amount)
Description copied from interface:ReadStreamFetch the specifiedamountof elements. If theReadStreamhas been paused, reading will recommence with the specifiedamountof items, otherwise the specifiedamountwill be added to the current stream demand.- Specified by:
fetchin interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
resume
public RecordParser resume()
Description copied from interface:ReadStreamResume reading, and sets the buffer inflowingmode. If theReadStreamhas been paused, reading will recommence on it.- Specified by:
resumein interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
public RecordParser endHandler(Handler<Void> endHandler)
Description copied from interface:ReadStreamSet an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.- Specified by:
endHandlerin interfaceReadStream<Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
newInstance
public static RecordParser newInstance(RecordParser arg)
-
-