Class ChainBuffer

java.lang.Object
nl.sidnlabs.pcap.decoder.ChainBuffer
All Implemented Interfaces:
Buffer

public class ChainBuffer extends Object implements Buffer
Author:
mindori
  • Constructor Details

    • ChainBuffer

      public ChainBuffer()
    • ChainBuffer

      public ChainBuffer(byte[] b)
    • ChainBuffer

      public ChainBuffer(Buffer other)
  • Method Details

    • getMetaData

      public int[] getMetaData()
      Specified by:
      getMetaData in interface Buffer
    • getBuffers

      public List<byte[]> getBuffers()
      Description copied from interface: Buffer
      Returns all internal chained byte buffers.
      Specified by:
      getBuffers in interface Buffer
      Returns:
      the byte buffer list.
    • getCapacity

      public int getCapacity()
      Specified by:
      getCapacity in interface Buffer
    • getBaseIndex

      public int getBaseIndex()
      Specified by:
      getBaseIndex in interface Buffer
    • getBaseOffset

      public int getBaseOffset()
      Specified by:
      getBaseOffset in interface Buffer
    • getBufIndex

      public int getBufIndex()
      Specified by:
      getBufIndex in interface Buffer
    • getOffset

      public int getOffset()
      Specified by:
      getOffset in interface Buffer
    • position

      public int position()
      Specified by:
      position in interface Buffer
    • position

      public Buffer position(int newPosition)
      Specified by:
      position in interface Buffer
    • addFirst

      public void addFirst(byte[] buffer)
      Description copied from interface: Buffer
      Add a byte buffer to head of internal buffer list.
      Specified by:
      addFirst in interface Buffer
      Parameters:
      buffer - the byte buffer that you want to add to head of internal buffers.
    • addLast

      public void addLast(byte[] buffer)
      Description copied from interface: Buffer
      Add a byte buffer to end of internal buffer list.
      Specified by:
      addLast in interface Buffer
      Parameters:
      buffer - the byte buffer that you want to add to end of internal buffers.
    • addFirst

      public void addFirst(Buffer buffer)
      Description copied from interface: Buffer
      Add all target's internal buffers to head of internal buffer list.
      Specified by:
      addFirst in interface Buffer
      Parameters:
      buffer - the buffer that you want to add to head of internal buffers.
    • addLast

      public void addLast(Buffer buffer)
      Description copied from interface: Buffer
      Add all target's inernal buffers to end of internal buffer list.
      Specified by:
      addLast in interface Buffer
      Parameters:
      buffer - the buffer that you want to add to end of internal buffers.
    • addLast

      public void addLast(Buffer buffer, int length)
      Specified by:
      addLast in interface Buffer
    • skip

      public Buffer skip(int pos)
      Specified by:
      skip in interface Buffer
    • get

      public byte get() throws BufferUnderflowException
      Description copied from interface: Buffer
      Get a byte from current position. Position will be increased.
      Specified by:
      get in interface Buffer
      Returns:
      a byte
      Throws:
      BufferUnderflowException - if position met end of buffers.
    • getShort

      public short getShort() throws BufferUnderflowException
      Description copied from interface: Buffer
      Get short from current position. Position will be increased.
      Specified by:
      getShort in interface Buffer
      Returns:
      short data
      Throws:
      BufferUnderflowException - if position met end of buffers.
    • getUnsignedShort

      public int getUnsignedShort()
      Specified by:
      getUnsignedShort in interface Buffer
    • getInt

      public int getInt() throws BufferUnderflowException
      Description copied from interface: Buffer
      Get integer from current position. Position will be increased.
      Specified by:
      getInt in interface Buffer
      Returns:
      integer data
      Throws:
      BufferUnderflowException - if position met end of buffers.
    • getUnsignedInt

      public long getUnsignedInt()
      Specified by:
      getUnsignedInt in interface Buffer
    • getLong

      public long getLong() throws BufferUnderflowException
      Description copied from interface: Buffer
      Get long from current position. Position will be increased.
      Specified by:
      getLong in interface Buffer
      Returns:
      long data
      Throws:
      BufferUnderflowException - if position met end of buffers.
    • getString

      public String getString(int length) throws BufferUnderflowException
      Description copied from interface: Buffer
      Get string from current position. Position will be increased.
      Specified by:
      getString in interface Buffer
      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: Buffer
      Get string from current position. Position will be increased.
      Specified by:
      getString in interface Buffer
      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: Buffer
      Get string from current position. Position will be increased.
      Specified by:
      getString in interface Buffer
      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: Buffer
      Get byte array from current position.
      Specified by:
      gets in interface Buffer
      Parameters:
      buffer - the output buffer
    • gets

      public void gets(byte[] buffer, int offset, int length) throws BufferUnderflowException
      Description copied from interface: Buffer
      Get byte array from current position.
      Specified by:
      gets in interface Buffer
      Parameters:
      buffer - the output buffer
      offset - the index of the first byte to fill
      length - the number of bytes to read
      Throws:
      BufferUnderflowException
    • bytesBefore

      public int bytesBefore(byte[] target)
      Description copied from interface: Buffer
      Find the first occurrence offset of the target byte pattern from current position.
      Specified by:
      bytesBefore in interface Buffer
      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: Buffer
      Mark current position. You can back to marked position using rewind call.
      Specified by:
      mark in interface Buffer
    • rewind

      public void rewind()
      Description copied from interface: Buffer
      Move current position to base position and the mark is discarded.
      Specified by:
      rewind in interface Buffer
    • reset

      public Buffer reset()
      Description copied from interface: Buffer
      Move current position to marked position.
      Specified by:
      reset in interface Buffer
      Returns:
    • reset

      public Buffer reset(int rewindOffset)
    • clean

      public void clean()
    • discardReadBytes

      public void discardReadBytes()
      Description copied from interface: Buffer
      Discard already read data. It will move base position.
      Specified by:
      discardReadBytes in interface Buffer
    • currentBuffer

      public byte[] currentBuffer()
      Description copied from interface: Buffer
      Returns the currently active backing buffer.
      Specified by:
      currentBuffer in interface Buffer
      Returns:
      byte[]
    • readableBytesCurrentBuffer

      public int readableBytesCurrentBuffer()
      Description copied from interface: Buffer
      Returns the number of bytes between the current position and the limit of the currently active backing buffer.
      Specified by:
      readableBytesCurrentBuffer in interface Buffer
      Returns:
      the number of bytes remaining in this buffer.
    • readableBytes

      public int readableBytes()
      Description copied from interface: Buffer
      Returns the number of bytes between the current position and the limit.
      Specified by:
      readableBytes in interface Buffer
      Returns:
      the number of bytes remaining in this buffer.
    • clear

      public Buffer clear()
      Description copied from interface: Buffer
      Clears this buffer. The position is set to zero and base position is set to zero too. and mark is discarded.
      Specified by:
      clear in interface Buffer
    • isEOB

      public boolean isEOB()
      Description copied from interface: Buffer
      Returns true if current position is after the last byte.
      Specified by:
      isEOB in interface Buffer
      Returns:
      True if current position is after the last byte
    • duplicate

      public Buffer duplicate()
      Specified by:
      duplicate in interface Buffer
    • flip

      public Buffer flip()
      Description copied from interface: Buffer
      Flips this buffer. The position is set to zero. If the mark is defined then it is discarded.
      Specified by:
      flip in interface Buffer