public interface MessageReader
DataMessage
which
allows 'relative' reading of the message without affecting the original
message pointers.
It should be noted that as a Message Reader maintains a reference to the original message then the original message can not be garbage collected until the reader itself is no longer referenced.
Modifier and Type | Method and Description |
---|---|
DataMessage |
getMessage()
Returns the message that this reader is for.
|
boolean |
hasRemaining()
Indicates whether the message has any remaining data to read.
|
byte |
nextByte()
Returns the next byte of data from the message.
|
void |
nextBytes(byte[] destination)
Returns data from the message as bytes from the current position.
|
String |
nextField()
Returns a field of string data from the current message position.
|
Record |
nextRecord()
Returns a record of string data from the current message position.
|
Record |
nextRecord(MRecord metadata)
Returns a record of string data from the current message position using
a Metadata definition.
|
int |
remaining()
Indicates the number of unread data bytes remaining within the message.
|
void |
rewind()
Resets the data pointer to the start of the data in preparation for
relative read ('next...') operations.
|
DataMessage getMessage()
byte nextByte() throws MessageException
The byte of data at the current position is returned and the position updated.
MessageException
- if unable to return the next byte of data.void nextBytes(byte[] destination) throws MessageException
Bytes from current message position are transferred into the specified destination array until the destination array is filled. The message position is then updated.
destination
- the destination array.MessageException
- if the destination array is too long.Record nextRecord() throws MessageException
This returns a record of String data read from the current data buffer position to the next record delimiter within the buffer or the end of the message.
Fields (areas delimited by field delimiters) are unpacked from within the record area. If there are no field delimiters then the returned record will contain only one field.
hasRemaining()
should be called before calling this method to
determine whether there is any data to read.
After calling this method the data buffer position will be moved beyond the record read.
MessageException
- if unable to obtain the next record.Record nextRecord(MRecord metadata) throws MessageException
This is similar to nextRecord()
except that the structure of the
supplied Metadata is assumed for the Record and the Record returned can
be accessed using Metadata specific methods.
metadata
- the Metadata that defines the Record. This must either
be a simple MRecord
definition or an MMessage
which
defines a single Record. The data type of the Metadata must be
TopicDataType.RECORD
.MessageException
- if unable to obtain the next record or the
Record data read violates the Metadata definition.String nextField() throws MessageException
This returns a field of String data constructed from bytes read from the current data buffer position to the next field delimiter (or record delimiter) within the buffer or the end of the message.
hasRemaining()
should be called before calling this method to
determine whether there is any data to read.
After calling this method the data buffer pointer will be moved beyond the delimiter found.
MessageException
- if unable to read the next field from the
record.void rewind()
boolean hasRemaining()
int remaining()
Copyright © 2016 Push Technology Ltd. All Rights Reserved.