public class DelimiterPacketReader extends java.lang.Object implements PacketReader
Since packets read with delimiters may potentially grow unbounded, you can also supply a maximum buffer size to prevent an attacker from causing an out of memory by continously sending data without the delimiter.
The delimiter will never appear in the packet itself.
SKIP_PACKET| Constructor and Description |
|---|
DelimiterPacketReader(byte delimiter)
Create a new reader with the default min buffer size and unlimited max buffer size.
|
DelimiterPacketReader(byte delimiter,
int maxPacketSize)
Create a new reader with the given min and max buffer size
delimited by the given byte.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getMaxPacketSize()
Get the current maximum buffer size.
|
byte[] |
nextPacket(java.nio.ByteBuffer byteBuffer)
Create a new packet using the ByteBuffer given.
|
void |
setMaxPacketSize(int maxPacketSize)
Set the new maximum packet size.
|
public DelimiterPacketReader(byte delimiter)
delimiter - the byte delimiter to use.public DelimiterPacketReader(byte delimiter,
int maxPacketSize)
delimiter - the byte value of the delimiter.maxPacketSize - the maximum number of bytes read before throwing an
IOException. -1 means the packet has no size limit.java.lang.IllegalArgumentException - if maxPacketSize < 1public int getMaxPacketSize()
public void setMaxPacketSize(int maxPacketSize)
This method is thread-safe, but will not affect reads in progress.
maxPacketSize - the new maximum packet size.public byte[] nextPacket(java.nio.ByteBuffer byteBuffer)
throws ProtocolViolationException
PacketReadernextPacket in interface PacketReaderbyteBuffer - the byte buffer to use.ProtocolViolationException - is there was an error constructing the packet.