Top Description Methods
io.vertx.core.parsetools

public Interface RecordParser

extends Handler<Buffer>, ReadStream<Buffer>
Known Direct Implementers
io.vertx.core.parsetools.impl.RecordParserImpl
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.Fluent, .VertxGen, io.vertx.core.Handler, io.vertx.core.buffer.Buffer, io.vertx.core.parsetools.impl.RecordParserImpl, io.vertx.core.streams.ReadStream

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 io.vertx.core.buffer.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.

Authors
Tim Fox, Lars Timm

Method Summary

Modifier and TypeMethod and Description
public void
delimitedMode(String
the new delimeter
delim
)

Flip the parser into delimited mode, and where the delimiter can be represented by the String delim encoded in latin-1 .

public void
delimitedMode(Buffer
the new delimiter
delim
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Flip the parser into delimited mode, and where the delimiter can be represented by the delimiter delim.

public RecordParser
endHandler(Handler<Void> endHandler)

public RecordParser
public RecordParser
fetch(long amount)

Redeclares io.vertx.core.streams.ReadStream.fetch.

Fetch the specified amount of elements.

public void
fixedSizeMode(int
the new record size
size
)

Flip the parser into fixed size mode, where the record size is specified by size in bytes.

public void
handle(Buffer
a chunk of data
buffer
)

Redeclares io.vertx.core.Handler.handle.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

This method is called to provide the parser with data.

public RecordParser
public RecordParser

Returns:

a reference to this, so the API can be used fluently
maxRecordSize
(int
the maximum record size
size
)

Set the maximum allowed size for a record when using the delimited mode.

public static RecordParser
newDelimited(String
the initial delimiter string
delim
,
Handler<Buffer>
handler that will receive the output
output
)

Like newDelimited(String) but set the output that will receive whole records which have been parsed.

public static RecordParser
newDelimited(String
the initial delimiter string
delim
,
ReadStream<Buffer>
the wrapped stream
stream
)

Like newDelimited(String) but wraps the stream.

public static RecordParser
newDelimited(String
the initial delimiter 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 .

public static RecordParser
newDelimited(Buffer
the initial delimiter buffer
delim
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented by the Buffer delim.

public static RecordParser
newDelimited(Buffer
the initial delimiter buffer
delim
,
Handler<Buffer>
handler that will receive the output
output
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like newDelimited(Buffer) but set the output that will receive whole records which have been parsed.

public static RecordParser
newDelimited(Buffer
the initial delimiter buffer
delim
,
ReadStream<Buffer>
the wrapped stream
stream
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like newDelimited(Buffer) but wraps the stream.

public static RecordParser
newFixed(int
the initial record size
size
)

Create a new RecordParser instance, initially in fixed size mode, and where the record size is specified by the size parameter.

public static RecordParser
newFixed(int
the initial record size
size
,
Handler<Buffer>
handler that will receive the output
output
)

Like newFixed(int) but set the output that will receive whole records which have been parsed.

public static RecordParser
newFixed(int
the initial record size
size
,
ReadStream<Buffer>
the wrapped stream
stream
)

Like newFixed(int) but wraps the stream.

public RecordParser
pause()

Redeclares io.vertx.core.streams.ReadStream.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

public RecordParser
resume()

Redeclares io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

public void
Inherited from io.vertx.core.streams.ReadStream:
collectendHandlerexceptionHandlerhandlerpipepipeTopipeTo

Method Detail

delimitedModeback to summary
public 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 . 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:String

the new delimeter

delimitedModeback to summary
public void delimitedMode(Buffer delim)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Flip the parser into delimited mode, and where the delimiter can be represented by the delimiter delim.

This method can be called multiple times with different values of delim while data is being parsed.

Parameters
delim:Buffer

the new delimiter

endHandlerback to summary
public RecordParser endHandler(Handler<Void> endHandler)
Annotations
@Override
exceptionHandlerback to summary
public RecordParser exceptionHandler(Handler<Throwable> handler)
Annotations
@Override
fetchback to summary
public RecordParser fetch(long amount)

Redeclares io.vertx.core.streams.ReadStream.fetch.

Doc from io.vertx.core.streams.ReadStream.fetch.

Fetch the specified 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.

Returns:RecordParser

a reference to this, so the API can be used fluently

Annotations
@Override
fixedSizeModeback to summary
public void fixedSizeMode(int size)

Flip the parser into fixed size mode, where the record size is specified by size in bytes.

This method can be called multiple times with different values of size while data is being parsed.

Parameters
size:int

the new record size

handleback to summary
public void handle(Buffer buffer)

Redeclares io.vertx.core.Handler.handle.

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This method is called to provide the parser with data.

Parameters
buffer:Buffer

a chunk of data

handlerback to summary
public RecordParser handler(Handler<Buffer> handler)
Annotations
@Override
maxRecordSizeback to summary
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 IllegalStateException will be thrown.

Parameters
size:int

the maximum record size

Returns:RecordParser

a reference to this, so the API can be used fluently

Annotations
@Fluent
newDelimitedback to summary
public static RecordParser newDelimited(String delim, Handler<Buffer> output)

Like newDelimited(String) but set the output that will receive whole records which have been parsed.

Parameters
delim:String

the initial delimiter string

output:Handler<Buffer>

handler that will receive the output

newDelimitedback to summary
public static RecordParser newDelimited(String delim, ReadStream<Buffer> stream)

Like newDelimited(String) but wraps the stream. The stream handlers will be set/unset when the handler(Handler) is set.

The pause()/resume() operations are propagated to the stream.

Parameters
delim:String

the initial delimiter string

stream:ReadStream<Buffer>

the wrapped stream

newDelimitedback to summary
public 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 . Don't use this if your String contains other than latin-1 characters.

output Will receive whole records which have been parsed.

Parameters
delim:String

the initial delimiter string

newDelimitedback to summary
public static RecordParser newDelimited(Buffer delim)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented by the Buffer delim.

Parameters
delim:Buffer

the initial delimiter buffer

newDelimitedback to summary
public static RecordParser newDelimited(Buffer delim, Handler<Buffer> output)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Like newDelimited(Buffer) but set the output that will receive whole records which have been parsed.

Parameters
delim:Buffer

the initial delimiter buffer

output:Handler<Buffer>

handler that will receive the output

newDelimitedback to summary
public static RecordParser newDelimited(Buffer delim, ReadStream<Buffer> stream)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Like newDelimited(Buffer) but wraps the stream. The stream handlers will be set/unset when the handler(Handler) is set.

The pause()/resume() operations are propagated to the stream.

Parameters
delim:Buffer

the initial delimiter buffer

stream:ReadStream<Buffer>

the wrapped stream

newFixedback to summary
public 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.

output Will receive whole records which have been parsed.

Parameters
size:int

the initial record size

newFixedback to summary
public static RecordParser newFixed(int size, Handler<Buffer> output)

Like newFixed(int) but set the output that will receive whole records which have been parsed.

Parameters
size:int

the initial record size

output:Handler<Buffer>

handler that will receive the output

newFixedback to summary
public static RecordParser newFixed(int size, ReadStream<Buffer> stream)

Like newFixed(int) but wraps the stream. The stream handlers will be set/unset when the handler(Handler) is set.

The pause()/resume() operations are propagated to the stream.

Parameters
size:int

the initial record size

stream:ReadStream<Buffer>

the wrapped stream

pauseback to summary
public RecordParser pause()

Redeclares io.vertx.core.streams.ReadStream.pause.

Doc from io.vertx.core.streams.ReadStream.pause.

Pause the 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.

Returns:RecordParser

a reference to this, so the API can be used fluently

Annotations
@Override
resumeback to summary
public RecordParser resume()

Redeclares io.vertx.core.streams.ReadStream.resume.

Doc from io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

If the ReadStream has been paused, reading will recommence on it.

Returns:RecordParser

a reference to this, so the API can be used fluently

Annotations
@Override
setOutputback to summary
public void setOutput(Handler<Buffer> output)