Package nl.sidnlabs.pcap.decoder
Class ChainBuffer
- java.lang.Object
-
- nl.sidnlabs.pcap.decoder.ChainBuffer
-
-
Constructor Summary
Constructors Constructor Description ChainBuffer()ChainBuffer(byte[] b)ChainBuffer(Buffer other)
-
Method Summary
All Methods Instance Methods Concrete 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.voidclean()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.Bufferreset(int rewindOffset)voidrewind()Move current position to base position and the mark is discarded.Bufferskip(int pos)
-
-
-
Constructor Detail
-
ChainBuffer
public ChainBuffer()
-
ChainBuffer
public ChainBuffer(byte[] b)
-
ChainBuffer
public ChainBuffer(Buffer other)
-
-
Method Detail
-
getMetaData
public int[] getMetaData()
- Specified by:
getMetaDatain interfaceBuffer
-
getBuffers
public List<byte[]> 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
-
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
public void addFirst(Buffer buffer)
Description copied from interface:BufferAdd all target's internal buffers to head of internal buffer list.
-
addLast
public void addLast(Buffer buffer)
Description copied from interface:BufferAdd all target's inernal buffers to end of internal buffer list.
-
get
public byte get() throws BufferUnderflowExceptionDescription 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
public short getShort() throws BufferUnderflowExceptionDescription 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
public int getInt() throws BufferUnderflowExceptionDescription 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
public long getLong() throws BufferUnderflowExceptionDescription 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
public String getString(int length) throws BufferUnderflowException
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
public String getString(int length, String charsetName) throws BufferUnderflowException
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
public String getString(int length, Charset charset) throws BufferUnderflowException
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
public void gets(byte[] buffer, int offset, int length) throws BufferUnderflowExceptionDescription 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
public Buffer reset()
Description copied from interface:BufferMove current position to marked position.
-
reset
public Buffer reset(int rewindOffset)
-
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
public 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.
-
-