|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnaga.packetreader.DelimiterPacketReader
public class DelimiterPacketReader
Class to read a byte stream delimited by a byte marking the end of a packet.
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.
Field Summary | |
---|---|
static int |
DEFAULT_READ_BUFFER_SIZE
|
Constructor Summary | |
---|---|
DelimiterPacketReader(byte delimiter)
Create a new reader with the default min buffer size and unlimited max buffer size. |
|
DelimiterPacketReader(byte delimiter,
int readBufferSize,
int maxPacketSize)
Create a new reader with the given min and max buffer size delimited by the given byte. |
Method Summary | |
---|---|
java.nio.ByteBuffer |
getBuffer()
Return the currently used byte buffer. |
int |
getMaxPacketSize()
Get the current maximum buffer size. |
byte[] |
getNextPacket()
Return the next packet constructed from the data read in the buffers. |
void |
setMaxPacketSize(int maxPacketSize)
Set the new maximum packet size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_READ_BUFFER_SIZE
Constructor Detail |
---|
public DelimiterPacketReader(byte delimiter)
delimiter
- the byte delimiter to use.public DelimiterPacketReader(byte delimiter, int readBufferSize, int maxPacketSize)
delimiter
- the byte value of the delimiter.readBufferSize
- the size of the read buffer (i.e. how many
bytes are read in a single pass) - this only has effect on read
efficiency and memory requirements.maxPacketSize
- the maximum number of bytes read before throwing a
ProtocolException. -1 means the packet has no size limit.
java.lang.IllegalArgumentException
- if maxPacketSize < readBufferSize or if
readBufferSize < 1.Method Detail |
---|
public 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 java.nio.ByteBuffer getBuffer() throws ProtocolViolationException
getBuffer
in interface PacketReader
ProtocolViolationException
- if the internal buffer already exceeds the maximum size.public byte[] getNextPacket() throws ProtocolViolationException
PacketReader
This call may or may not have been proceeded by a call to getBuffer().
The calling thread will call this method repeatedly until it returns null.
getNextPacket
in interface PacketReader
ProtocolViolationException
- if a protocol violation was detected when
parsing the next packet.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |