Package nl.sidnlabs.pcap.decoder
Interface Buffer
-
- All Known Implementing Classes:
ChainBuffer
public interface Buffer- Author:
- mindori
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddFirst(byte[] buffer)Add a byte buffer to head of internal buffer list.voidaddFirst(Buffer buffer)Add all target's internal buffers to head of internal buffer list.voidaddLast(byte[] buffer)Add a byte buffer to end of internal buffer list.voidaddLast(Buffer buffer)Add all target's inernal buffers to end of internal buffer list.voidaddLast(Buffer buffer, int length)intbytesBefore(byte[] target)Find the first occurrence offset of the target byte pattern from current position.Bufferclear()Clears this buffer.byte[]currentBuffer()Returns the currently active backing buffer.voiddiscardReadBytes()Discard already read data.Bufferduplicate()Bufferflip()Flips this buffer.byteget()Get a byte from current position.intgetBaseIndex()intgetBaseOffset()List<byte[]>getBuffers()Returns all internal chained byte buffers.intgetBufIndex()intgetCapacity()intgetInt()Get integer from current position.longgetLong()Get long from current position.int[]getMetaData()intgetOffset()voidgets(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.StringgetString(int length)Get string from current position.StringgetString(int length, String charsetName)Get string from current position.StringgetString(int length, Charset charset)Get string from current position.longgetUnsignedInt()intgetUnsignedShort()booleanisEOB()Returns true if current position is after the last byte.voidmark()Mark current position.intposition()Bufferposition(int newPosition)intreadableBytes()Returns the number of bytes between the current position and the limit.intreadableBytesCurrentBuffer()Returns the number of bytes between the current position and the limit of the currently active backing buffer.Bufferreset()Move current position to marked position.voidrewind()Move current position to base position and the mark is discarded.Bufferskip(int pos)
-
-
-
Method Detail
-
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
Buffer position(int newPosition)
-
addFirst
void addFirst(Buffer buffer)
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
void addLast(Buffer buffer)
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
void addLast(Buffer buffer, int length)
-
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
Buffer skip(int pos)
-
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
String getString(int length)
Get string from current position. Position will be increased.- Returns:
- string data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getString
String getString(int length, String charsetName)
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
String getString(int length, Charset charset)
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.
-
-