Package nl.sidnlabs.pcap.decoder
Class ChainBuffer
java.lang.Object
nl.sidnlabs.pcap.decoder.ChainBuffer
- All Implemented Interfaces:
Buffer
- Author:
- mindori
-
Constructor Summary
Constructors -
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.voidclean()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.reset(int rewindOffset) voidrewind()Move current position to base position and the mark is discarded.skip(int pos)
-
Constructor Details
-
ChainBuffer
public ChainBuffer() -
ChainBuffer
public ChainBuffer(byte[] b) -
ChainBuffer
-
-
Method Details
-
getMetaData
public int[] getMetaData()- Specified by:
getMetaDatain interfaceBuffer
-
getBuffers
Description copied from interface:BufferReturns all internal chained byte buffers.- Specified by:
getBuffersin interfaceBuffer- Returns:
- the byte buffer list.
-
getCapacity
public int getCapacity()- Specified by:
getCapacityin interfaceBuffer
-
getBaseIndex
public int getBaseIndex()- Specified by:
getBaseIndexin interfaceBuffer
-
getBaseOffset
public int getBaseOffset()- Specified by:
getBaseOffsetin interfaceBuffer
-
getBufIndex
public int getBufIndex()- Specified by:
getBufIndexin interfaceBuffer
-
getOffset
public int getOffset() -
position
public int position() -
position
-
addFirst
public void addFirst(byte[] buffer) Description copied from interface:BufferAdd a byte buffer to head of internal buffer list. -
addLast
public void addLast(byte[] buffer) Description copied from interface:BufferAdd a byte buffer to end of internal buffer list. -
addFirst
Description copied from interface:BufferAdd all target's internal buffers to head of internal buffer list. -
addLast
Description copied from interface:BufferAdd all target's inernal buffers to end of internal buffer list. -
addLast
-
skip
-
get
Description copied from interface:BufferGet a byte from current position. Position will be increased.- Specified by:
getin interfaceBuffer- Returns:
- a byte
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getShort
Description copied from interface:BufferGet short from current position. Position will be increased.- Specified by:
getShortin interfaceBuffer- Returns:
- short data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getUnsignedShort
public int getUnsignedShort()- Specified by:
getUnsignedShortin interfaceBuffer
-
getInt
Description copied from interface:BufferGet integer from current position. Position will be increased.- Specified by:
getIntin interfaceBuffer- Returns:
- integer data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getUnsignedInt
public long getUnsignedInt()- Specified by:
getUnsignedIntin interfaceBuffer
-
getLong
Description copied from interface:BufferGet long from current position. Position will be increased.- Specified by:
getLongin interfaceBuffer- Returns:
- long data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getString
Description copied from interface:BufferGet string from current position. Position will be increased.- Specified by:
getStringin interfaceBuffer- Returns:
- string data
- Throws:
BufferUnderflowException- if position met end of buffers.
-
getString
Description copied from interface:BufferGet string from current position. Position will be increased.- Specified by:
getStringin interfaceBuffer- 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
Description copied from interface:BufferGet string from current position. Position will be increased.- Specified by:
getStringin interfaceBuffer- 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
public void gets(byte[] buffer) Description copied from interface:BufferGet byte array from current position. -
gets
Description copied from interface:BufferGet byte array from current position.- Specified by:
getsin interfaceBuffer- Parameters:
buffer- the output bufferoffset- the index of the first byte to filllength- the number of bytes to read- Throws:
BufferUnderflowException
-
bytesBefore
public int bytesBefore(byte[] target) Description copied from interface:BufferFind the first occurrence offset of the target byte pattern from current position.- Specified by:
bytesBeforein interfaceBuffer- 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.
-
mark
public void mark()Description copied from interface:BufferMark current position. You can back to marked position using rewind call. -
rewind
public void rewind()Description copied from interface:BufferMove current position to base position and the mark is discarded. -
reset
Description copied from interface:BufferMove current position to marked position. -
reset
-
clean
public void clean() -
discardReadBytes
public void discardReadBytes()Description copied from interface:BufferDiscard already read data. It will move base position.- Specified by:
discardReadBytesin interfaceBuffer
-
currentBuffer
public byte[] currentBuffer()Description copied from interface:BufferReturns the currently active backing buffer.- Specified by:
currentBufferin interfaceBuffer- Returns:
- byte[]
-
readableBytesCurrentBuffer
public int readableBytesCurrentBuffer()Description copied from interface:BufferReturns the number of bytes between the current position and the limit of the currently active backing buffer.- Specified by:
readableBytesCurrentBufferin interfaceBuffer- Returns:
- the number of bytes remaining in this buffer.
-
readableBytes
public int readableBytes()Description copied from interface:BufferReturns the number of bytes between the current position and the limit.- Specified by:
readableBytesin interfaceBuffer- Returns:
- the number of bytes remaining in this buffer.
-
clear
Description copied from interface:BufferClears this buffer. The position is set to zero and base position is set to zero too. and mark is discarded. -
isEOB
public boolean isEOB()Description copied from interface:BufferReturns true if current position is after the last byte. -
duplicate
-
flip
Description copied from interface:BufferFlips this buffer. The position is set to zero. If the mark is defined then it is discarded.
-