|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.vertx.groovy.core.parsetools.RecordParser
class RecordParser
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:\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. TODO extend this class to cope with arbitrary character encodings
Method Summary | |
---|---|
void
|
delimitedMode(java.lang.String delim)
Flip the parser into delimited mode, and where the delimiter can be represented by the String delim endcoded in latin-1 . |
void
|
delimitedMode(byte[] delim)
Flip the parser into delimited mode, and where the delimiter can be represented by the delimiter delim. |
void
|
fixedSizeMode(int size)
Flip the parser into fixed size mode, where the record size is specified by size in bytes. |
void
|
handle(Buffer data)
|
static byte[]
|
latin1StringToBytes(java.lang.String str)
Helper method to convert a latin-1 String to an array of bytes for use as a delimiter Please do not use this for non latin-1 characters |
static RecordParser
|
newDelimited(java.lang.String delim, groovy.lang.Closure output)
Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented by the String {@code} delim endcoded in latin-1 . |
static RecordParser
|
newDelimited(byte[] delim, groovy.lang.Closure output)
Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented by the byte[] delim. |
static RecordParser
|
newFixed(int size, groovy.lang.Closure output)
Create a new RecordParser instance, initially in fixed size mode, and where the record size is specified by the size parameter. |
void
|
setOutput(groovy.lang.Closure output)
|
groovy.lang.Closure
|
toClosure()
Convert to a closure so it can be plugged into data handlers |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Method Detail |
---|
void delimitedMode(java.lang.String delim)
This method can be called multiple times with different values of delim while data is being parsed.
void delimitedMode(byte[] delim)
This method can be called multiple times with different values of delim while data is being parsed.
void fixedSizeMode(int size)
This method can be called multiple times with different values of size while data is being parsed.
void handle(Buffer data)
static byte[] latin1StringToBytes(java.lang.String str)
static RecordParser newDelimited(java.lang.String delim, groovy.lang.Closure output)
output Will receive whole records which have been parsed.
static RecordParser newDelimited(byte[] delim, groovy.lang.Closure output)
output Will receive whole records which have been parsed.
static RecordParser newFixed(int size, groovy.lang.Closure output)
output Will receive whole records which have been parsed.
void setOutput(groovy.lang.Closure output)
groovy.lang.Closure toClosure()
Groovy Documentation