Package nl.sidnlabs.pcap.decoder
Interface Buffer
- All Known Implementing Classes:
ChainBuffer
public interface Buffer
- Author:
- mindori
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddFirst(byte[] buffer) Add a byte buffer to head of internal buffer list.voidAdd all target's internal buffers to head of internal buffer list.voidaddLast(byte[] buffer) Add a byte buffer to end of internal buffer list.voidAdd all target's inernal buffers to end of internal buffer list.voidintbytesBefore(byte[] target) Find the first occurrence offset of the target byte pattern from current position.clear()Clears this buffer.byte[]Returns the currently active backing buffer.voidDiscard already read data.flip()Flips this buffer.byteget()Get a byte from current position.intintList<byte[]>Returns all internal chained byte buffers.intintintgetInt()Get integer from current position.longgetLong()Get long from current position.int[]intvoidgets(byte[] buffer) Get byte array from current position.voidgets(byte[] buffer, int offset, int length) Get byte array from current position.shortgetShort()Get short from current position.getString(int length) Get string from current position.Get string from current position.Get string from current position.longintbooleanisEOB()Returns true if current position is after the last byte.voidmark()Mark current position.intposition()position(int newPosition) intReturns the number of bytes between the current position and the limit.intReturns the number of bytes between the current position and the limit of the currently active backing buffer.reset()Move current position to marked position.voidrewind()Move current position to base position and the mark is discarded.skip(int pos)
-
Method Details
-
getBuffers
List<byte[]> getBuffers()Returns all internal chained byte buffers.- Returns:
- the byte buffer list.
-
getMetaData
int[] getMetaData() -
getCapacity
int getCapacity() -
getBaseIndex
int getBaseIndex() -
getBaseOffset
int getBaseOffset() -
getBufIndex
int getBufIndex() -
getOffset
int getOffset() -
position
int position() -
position
-
addFirst
Add all target's internal buffers to head of internal buffer list.- Parameters:
buffer- the buffer that you want to add to head of internal buffers.
-
addLast
Add all target's inernal buffers to end of internal buffer list.- Parameters:
buffer- the buffer that you want to add to end of internal buffers.
-
addLast
-
addFirst
void addFirst(byte[] buffer) Add a byte buffer to head of internal buffer list.- Parameters:
buffer- the byte buffer that you want to add to head of internal buffers.
-
addLast
void addLast(byte[] buffer) Add a byte buffer to end of internal buffer list.- Parameters:
buffer- the byte buffer that you want to add to end of internal buffers.
-
skip
-
get
byte get()Get a byte from current position. Position will be increased.- Returns:
- a byte
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getShort
short getShort()Get short from current position. Position will be increased.- Returns:
- short data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getUnsignedShort
int getUnsignedShort() -
getInt
int getInt()Get integer from current position. Position will be increased.- Returns:
- integer data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getUnsignedInt
long getUnsignedInt() -
getLong
long getLong()Get long from current position. Position will be increased.- Returns:
- long data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getString
Get string from current position. Position will be increased.- Returns:
- string data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getString
Get string from current position. Position will be increased.- Parameters:
length- the string length that you want to read.charsetName- the charset name for decoding.- Returns:
- string data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getString
Get string from current position. Position will be increased.- Parameters:
length- the string length that you want to read.charset- the charset for decoding.- Returns:
- string data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
gets
void gets(byte[] buffer) Get byte array from current position.- Parameters:
buffer- the output buffer
-
gets
void gets(byte[] buffer, int offset, int length) Get byte array from current position.- Parameters:
buffer- the output bufferoffset- the index of the first byte to filllength- the number of bytes to read
-
mark
void mark()Mark current position. You can back to marked position using rewind call. -
discardReadBytes
void discardReadBytes()Discard already read data. It will move base position. -
rewind
void rewind()Move current position to base position and the mark is discarded. -
reset
Buffer reset()Move current position to marked position.- Returns:
-
bytesBefore
int bytesBefore(byte[] target) Find the first occurrence offset of the target byte pattern from current position.- Parameters:
target- the byte pattern that you want to search for.- Returns:
- the offset from current position, first offset of the target pattern. for example, if you call bytesBefore('\r\n') for 'hello\r\n', it will return 5.
-
readableBytes
int readableBytes()Returns the number of bytes between the current position and the limit.- Returns:
- the number of bytes remaining in this buffer.
-
readableBytesCurrentBuffer
int readableBytesCurrentBuffer()Returns the number of bytes between the current position and the limit of the currently active backing buffer.- Returns:
- the number of bytes remaining in this buffer.
-
currentBuffer
byte[] currentBuffer()Returns the currently active backing buffer.- Returns:
- byte[]
-
clear
Buffer clear()Clears this buffer. The position is set to zero and base position is set to zero too. and mark is discarded. -
isEOB
boolean isEOB()Returns true if current position is after the last byte.- Returns:
- True if current position is after the last byte
-
duplicate
Buffer duplicate() -
flip
Buffer flip()Flips this buffer. The position is set to zero. If the mark is defined then it is discarded.
-