Class ReusableBuffer

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

public class ReusableBuffer extends Object
A reusable buffer of bytes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new ReusableBuffer using the default transfer buffer size.
    ReusableBuffer(byte[] bytes)
    Constructs a new ReusableBuffer wrapping the given byte array.
    ReusableBuffer(byte[] data, int offset, int length)
    Constructs a new ReusableBuffer wrapping a segment of the given byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the underlying byte array.
    void
    initSize(int length)
    Initializes the buffer to the given size if it is larger than the current size.
    int
    Returns the length of the valid data in the buffer.
    int
    Returns the offset of the data within the underlying byte array.
    void
    Writes the logical contents of this buffer to an output stream.

    Methods inherited from class java.lang.Object

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

    • ReusableBuffer

      public ReusableBuffer()
      Constructs a new ReusableBuffer using the default transfer buffer size.
    • ReusableBuffer

      public ReusableBuffer(byte[] bytes)
      Constructs a new ReusableBuffer wrapping the given byte array.
      Parameters:
      bytes - the byte array to wrap
    • ReusableBuffer

      public ReusableBuffer(byte[] data, int offset, int length)
      Constructs a new ReusableBuffer wrapping a segment of the given byte array.
      Parameters:
      data - the byte array
      offset - the start offset in the byte array
      length - the number of bytes to use
  • Method Details

    • initSize

      public void initSize(int length)
      Initializes the buffer to the given size if it is larger than the current size.
      Parameters:
      length - the required minimum length
    • offset

      public int offset()
      Returns the offset of the data within the underlying byte array.
      Returns:
      the offset
    • length

      public int length()
      Returns the length of the valid data in the buffer.
      Returns:
      the length
    • data

      public byte[] data()
      Returns the underlying byte array.
      Returns:
      the raw data array
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Writes the logical contents of this buffer to an output stream.
      Parameters:
      out - the output stream to write to
      Throws:
      IOException - if an error occurs writing to the stream