Class ReusableBufferList

java.lang.Object
net.targetr.wtm3.io.ReusableBufferList

public class ReusableBufferList extends Object
A list of reusable buffers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new empty ReusableBufferList.
    ReusableBufferList(byte[] data)
    Constructs a new ReusableBufferList with a single byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(byte[] data)
    Adds a byte array to the list.
    void
    add(byte[] data, int offset, int length)
    Adds a segment of a byte array to the list.
    void
    Adds a reusable buffer to the list.
    void
    Adds all buffers from another list to this list.
    void
    Clears all buffers from this list.
    split(byte splitByte)
    Splits this buffer list into two lists.
    byte[]
    Creates a single byte array containing all data from the buffers.
    int
    Calculates the total size in bytes of all buffers in the list.
    void
    Writes all buffers in this list to the given output stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReusableBufferList

      public ReusableBufferList()
      Constructs a new empty ReusableBufferList.
    • ReusableBufferList

      public ReusableBufferList(byte[] data)
      Constructs a new ReusableBufferList with a single byte array.
      Parameters:
      data - the initial byte array
  • Method Details

    • add

      public void add(byte[] data)
      Adds a byte array to the list.
      Parameters:
      data - the byte array to add
    • add

      public void add(byte[] data, int offset, int length)
      Adds a segment of a byte array to the list.
      Parameters:
      data - the byte array
      offset - the offset in the byte array
      length - the length to add
    • add

      public void add(ReusableBuffer buffer)
      Adds a reusable buffer to the list.
      Parameters:
      buffer - the buffer to add
    • add

      public void add(ReusableBufferList buffers)
      Adds all buffers from another list to this list.
      Parameters:
      buffers - the list of buffers to add
    • totalSizeInBytes

      public int totalSizeInBytes()
      Calculates the total size in bytes of all buffers in the list.
      Returns:
      the total size in bytes
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Writes all buffers in this list to the given output stream.
      Parameters:
      out - the output stream to write to
      Throws:
      IOException - if an I/O error occurs
    • toByteArray

      public byte[] toByteArray()
      Creates a single byte array containing all data from the buffers.
      Returns:
      a single byte array containing all the data
    • clear

      public void clear()
      Clears all buffers from this list.
    • split

      public ReusableBufferList[] split(byte splitByte)
      Splits this buffer list into two lists. The first list will be up to split byte and the second list will be after split byte.
      Parameters:
      splitByte - the byte value to split on
      Returns:
      an array containing two ReusableBufferLists: the first part and second part