Class BoundedByteArrayOutputStream

java.lang.Object
java.io.OutputStream
org.apache.hadoop.io.BoundedByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

@LimitedPrivate({"HDFS","MapReduce"}) @Unstable public class BoundedByteArrayOutputStream extends OutputStream
A byte array backed output stream with a limit. The limit should be smaller than the buffer capacity. The object can be reused through reset API and choose different limits in each round.
  • Constructor Details

    • BoundedByteArrayOutputStream

      public BoundedByteArrayOutputStream(int capacity)
      Create a BoundedByteArrayOutputStream with the specified capacity
      Parameters:
      capacity - The capacity of the underlying byte array
    • BoundedByteArrayOutputStream

      public BoundedByteArrayOutputStream(int capacity, int limit)
      Create a BoundedByteArrayOutputStream with the specified capacity and limit.
      Parameters:
      capacity - The capacity of the underlying byte array
      limit - The maximum limit upto which data can be written
    • BoundedByteArrayOutputStream

      protected BoundedByteArrayOutputStream(byte[] buf, int offset, int limit)
  • Method Details

    • resetBuffer

      protected void resetBuffer(byte[] buf, int offset, int limit)
    • write

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

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • reset

      public void reset(int newlim)
      Reset the limit
      Parameters:
      newlim - New Limit
    • reset

      public void reset()
      Reset the buffer
    • getLimit

      public int getLimit()
      Return the current limit.
      Returns:
      limit.
    • getBuffer

      public byte[] getBuffer()
      Returns the underlying buffer. Data is only valid to size().
      Returns:
      the underlying buffer.
    • size

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

      public int available()