Class UnsynchronizedBuffer

java.lang.Object
java.io.OutputStream
org.apache.calcite.avatica.util.UnsynchronizedBuffer
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class UnsynchronizedBuffer extends OutputStream
A utility class for reading and writing bytes to byte buffers without synchronization. A reduced variant taken from Apache Accumulo. This class is not thread-safe by design. It is up to the caller to guarantee mutual exclusion as necessary.
  • Constructor Details

    • UnsynchronizedBuffer

      public UnsynchronizedBuffer()
      Creates a new writer.
    • UnsynchronizedBuffer

      public UnsynchronizedBuffer(int initialCapacity)
      Creates a new writer.
      Parameters:
      initialCapacity - initial byte capacity
  • Method Details

    • write

      public void write(byte[] bytes, int off, int length)
      Adds bytes to this writer's buffer.
      Overrides:
      write in class OutputStream
      Parameters:
      bytes - byte array
      off - offset into array to start copying bytes
      length - number of bytes to add
      Throws:
      IndexOutOfBoundsException - if off or length are invalid
    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • toArray

      public byte[] toArray()
      Gets (a copy of) the contents of this writer's buffer.
      Returns:
      byte buffer contents
    • reset

      public void reset()
      Resets the internal pointer into the buffer.
    • getOffset

      public int getOffset()
      Returns:
      The current offset into the backing array.
    • getSize

      public long getSize()
      Returns:
      The current length of the backing array.
    • nextArraySize

      public static int nextArraySize(int i)
      Determines what next array size should be by rounding up to next power of two.
      Parameters:
      i - current array size
      Returns:
      next array size
      Throws:
      IllegalArgumentException - if i is negative