BoundedByteArrayOutputStream (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.io, class: BoundedByteArrayOutputStream

Package org.apache.hadoop.io

# 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 Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `BoundedByteArrayOutputStream(byte[] buf, int offset, int limit)`
  ``
  `BoundedByteArrayOutputStream(int capacity)`
  Create a BoundedByteArrayOutputStream with the specified capacity
  ``
  `BoundedByteArrayOutputStream(int capacity, int limit)`
  Create a BoundedByteArrayOutputStream with the specified capacity and limit.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `available()`
  `byte[]`
  `getBuffer()`
  Returns the underlying buffer.
  `int`
  `getLimit()`
  Return the current limit.
  `void`
  `reset()`
  Reset the buffer
  `void`
  `reset(int newlim)`
  Reset the limit
  `protected void`
  `resetBuffer(byte[] buf, int offset, int limit)`
  `int`
  `size()`
  Returns the length of the valid data currently in the buffer.
  `void`
  `write(byte[] b, int off, int len)`
  `void`
  `write(int b)`

  ### Methods inherited from class java.io.OutputStream

  `close, flush, nullOutputStream, write`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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()