Class RecordParser
- All Implemented Interfaces:
MutinyDelegate,io.vertx.core.Handler<io.vertx.core.buffer.Buffer>,ReadStream<io.vertx.core.buffer.Buffer>,StreamBase,Consumer<io.vertx.core.buffer.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 the original non Mutiny-ified interface.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.vertx.mutiny.core.streams.ReadStream
ReadStream.ReadStreamImpl<T>Nested classes/interfaces inherited from interface io.vertx.mutiny.core.streams.StreamBase
StreamBase.StreamBaseImpl -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRecordParser(io.vertx.core.parsetools.RecordParser delegate) Create a new instance ofRecordParserdelegating to the given (non-null) instance ofRecordParser.RecordParser(Object delegate) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(io.vertx.core.buffer.Buffer item) Handle an item.voiddelimitedMode(io.vertx.core.buffer.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 .endHandler(Runnable endHandler) Set an end handler.booleanexceptionHandler(Consumer<Throwable> handler) Set an exception handler on the read stream.fetch(long amount) Fetch the specifiedamountof elements.voidfixedSizeMode(int size) Flip the parser into fixed size mode, where the record size is specified bysizein bytes.io.vertx.core.parsetools.RecordParserGet the delegate instance.voidhandle(io.vertx.core.buffer.Buffer buffer) This method is called to provide the parser with data.Set a data handler.inthashCode()maxRecordSize(int size) Set the maximum allowed size for a record when using the delimited mode.static RecordParsernewDelimited(io.vertx.core.buffer.Buffer delim) Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by theBufferdelim.static RecordParsernewDelimited(io.vertx.core.buffer.Buffer delim, ReadStream<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(Buffer)but wraps thestream.static RecordParsernewDelimited(io.vertx.core.buffer.Buffer delim, Flow.Publisher<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(Buffer)but wraps thestream.static RecordParsernewDelimited(io.vertx.core.buffer.Buffer delim, Consumer<io.vertx.core.buffer.Buffer> output) LikenewDelimited(Buffer)but set theoutputthat will receive whole records which have been parsed.static RecordParsernewDelimited(String delim) Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by the String delim endcoded in latin-1 .static RecordParsernewDelimited(String delim, ReadStream<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(String)but wraps thestream.static RecordParsernewDelimited(String delim, Flow.Publisher<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(String)but wraps thestream.static RecordParsernewDelimited(String delim, Consumer<io.vertx.core.buffer.Buffer> output) LikenewDelimited(String)but set theoutputthat will receive whole records which have been parsed.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, ReadStream<io.vertx.core.buffer.Buffer> stream) LikenewFixed(int)but wraps thestream.static RecordParsernewFixed(int size, Flow.Publisher<io.vertx.core.buffer.Buffer> stream) LikenewFixed(int)but wraps thestream.static RecordParserLikenewFixed(int)but set theoutputthat will receive whole records which have been parsed.static RecordParsernewInstance(io.vertx.core.parsetools.RecordParser delegate) Creates a new instance of theRecordParser.pause()Pause theReadStream, it sets the buffer infetchmode and clears the actual demand.Pipe<io.vertx.core.buffer.Buffer>pipe()Pause this stream and return aPipeto transfer the elements of this stream to a destinationWriteStream.io.smallrye.mutiny.Uni<Void>pipeTo(WriteStream<io.vertx.core.buffer.Buffer> arg0) Pipe thisReadStreamto theWriteStream.voidpipeToAndAwait(WriteStream<io.vertx.core.buffer.Buffer> arg0) Pipe thisReadStreamto theWriteStream.pipeToAndForget(WriteStream<io.vertx.core.buffer.Buffer> arg0) Pipe thisReadStreamto theWriteStream.resume()Resume reading, and sets the buffer inflowingmode.voidIterable<io.vertx.core.buffer.Buffer>Stream<io.vertx.core.buffer.Buffer>io.smallrye.mutiny.Multi<io.vertx.core.buffer.Buffer>toMulti()toString()
-
Field Details
-
__TYPE_ARG
-
-
Constructor Details
-
RecordParser
public RecordParser(io.vertx.core.parsetools.RecordParser delegate) Create a new instance ofRecordParserdelegating to the given (non-null) instance ofRecordParser. -
RecordParser
-
-
Method Details
-
accept
public void accept(io.vertx.core.buffer.Buffer item) Handle an item. This method is generated from theoriginalmethod." -
getDelegate
public io.vertx.core.parsetools.RecordParser getDelegate()Get the delegate instance.This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.
- Specified by:
getDelegatein interfaceMutinyDelegate- Specified by:
getDelegatein interfaceReadStream<io.vertx.core.buffer.Buffer>- Specified by:
getDelegatein interfaceStreamBase- Returns:
- the delegate instance
-
pipeTo
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<io.vertx.core.buffer.Buffer> arg0) Pipe thisReadStreamto theWriteStream.Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Unlike the bare Vert.x variant, this method returns a
Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.Don't forget to subscribe on it to trigger the operation.
- Specified by:
pipeToin interfaceReadStream<io.vertx.core.buffer.Buffer>- Parameters:
dst- the destination write stream- Returns:
- A
Unirepresenting the asynchronous result of this operation. - See Also:
-
io.vertx.core.parsetools.RecordParser#pipeTo(WriteStream)
-
pipeToAndAwait
Pipe thisReadStreamto theWriteStream.Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Unlike the bare Vert.x variant, this method returns a
Void. This method awaits indefinitely 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 aRuntimeException).- Parameters:
dst- the destination write stream- See Also:
-
io.vertx.core.parsetools.RecordParser#pipeTo(WriteStream)
-
pipeToAndForget
Pipe thisReadStreamto theWriteStream.Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Unlike the bare Vert.x variant, this method ignores the
Voidresult or any failure.- Parameters:
dst- the destination write stream- Returns:
- The current instance to chain operations if needed.
- See Also:
-
io.vertx.core.parsetools.RecordParser#pipeTo(WriteStream)
-
setOutput
-
newDelimited
LikenewDelimited(String)but set theoutputthat will receive whole records which have been parsed.- Parameters:
delim- the initial delimiter stringoutput- handler that will receive the output
-
newDelimited
public static RecordParser newDelimited(String delim, ReadStream<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(String)but wraps thestream. Thestreamhandlers will be set/unset when the#handler(Handler)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter stringstream- the wrapped stream
-
newDelimited
public static RecordParser newDelimited(String delim, Flow.Publisher<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(String)but wraps thestream. Thestreamhandlers will be set/unset when the#handler(Handler)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter stringstream- the wrapped stream
-
newDelimited
Create a newRecordParserinstance, 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.outputWill receive whole records which have been parsed.- Parameters:
delim- the initial delimiter string
-
newDelimited
Create a newRecordParserinstance, initially in delimited mode, and where the delimiter can be represented by theBufferdelim.- Parameters:
delim- the initial delimiter buffer
-
newDelimited
public static RecordParser newDelimited(io.vertx.core.buffer.Buffer delim, Consumer<io.vertx.core.buffer.Buffer> output) LikenewDelimited(Buffer)but set theoutputthat will receive whole records which have been parsed.- Parameters:
delim- the initial delimiter bufferoutput- handler that will receive the output
-
newDelimited
public static RecordParser newDelimited(io.vertx.core.buffer.Buffer delim, ReadStream<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(Buffer)but wraps thestream. Thestreamhandlers will be set/unset when the#handler(Handler)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter bufferstream- the wrapped stream
-
newDelimited
public static RecordParser newDelimited(io.vertx.core.buffer.Buffer delim, Flow.Publisher<io.vertx.core.buffer.Buffer> stream) LikenewDelimited(Buffer)but wraps thestream. Thestreamhandlers will be set/unset when the#handler(Handler)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
delim- the initial delimiter bufferstream- the wrapped stream
-
newFixed
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
-
newFixed
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
-
newFixed
LikenewFixed(int)but wraps thestream. Thestreamhandlers will be set/unset when the#handler(Handler)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
size- the initial record sizestream- the wrapped stream
-
newFixed
LikenewFixed(int)but wraps thestream. Thestreamhandlers will be set/unset when the#handler(Handler)is set. Thepause()/resume()operations are propagated to thestream.- Parameters:
size- the initial record sizestream- the wrapped stream
-
delimitedMode
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(io.vertx.core.buffer.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
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(io.vertx.core.buffer.Buffer buffer) This method is called to provide the parser with data.- Specified by:
handlein interfaceio.vertx.core.Handler<io.vertx.core.buffer.Buffer>- Parameters:
buffer- a chunk of data
-
exceptionHandler
Description copied from interface:ReadStreamSet an exception handler on the read stream.- Specified by:
exceptionHandlerin interfaceReadStream<io.vertx.core.buffer.Buffer>- Specified by:
exceptionHandlerin interfaceStreamBase- Parameters:
handler- the exception handler. Can benull.- Returns:
- a reference to this, so the API can be used fluently
-
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<io.vertx.core.buffer.Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
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<io.vertx.core.buffer.Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
fetch
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<io.vertx.core.buffer.Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
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<io.vertx.core.buffer.Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
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<io.vertx.core.buffer.Buffer>- Returns:
- a reference to this, so the API can be used fluently
-
pipe
Pause this stream and return aPipeto transfer the elements of this stream to a destinationWriteStream. The stream will be resumed when the pipe will be wired to aWriteStream.- Specified by:
pipein interfaceReadStream<io.vertx.core.buffer.Buffer>- Returns:
- a pipe
-
newInstance
Creates a new instance of theRecordParser. -
hashCode
public int hashCode() -
equals
-
toString
-
toMulti
@CheckReturnValue public io.smallrye.mutiny.Multi<io.vertx.core.buffer.Buffer> toMulti() -
toBlockingIterable
-
toBlockingStream
-