org.springframework.util

## Class ResizableByteArrayOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.ByteArrayOutputStream
    - - org.springframework.util.ResizableByteArrayOutputStream

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

      public class ResizableByteArrayOutputStream
      extends ByteArrayOutputStream

  An extension of `ByteArrayOutputStream` that:
  - has public `grow(int)` and `resize(int)` methods to get more control over the the size of the internal buffer
  - has a higher initial capacity (256) by default
  Since:
    4.0
  Author:
    Brian Clozel, Juergen Hoeller

- - ### Field Summary

    - ### Fields inherited from class java.io.ByteArrayOutputStream

      `buf, count`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResizableByteArrayOutputStream()` Create a new `ResizableByteArrayOutputStream` with the default initial capacity of 128 bytes.
    `ResizableByteArrayOutputStream(int initialCapacity)` Create a new `ResizableByteArrayOutputStream` with the specified initial capacity.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `capacity()` Return the current size of this stream's internal buffer.
    `void` | `grow(int additionalCapacity)` Grow the internal buffer size.
    `void` | `resize(int targetCapacity)` Resize the internal buffer size to a specified capacity.

    - ### Methods inherited from class java.io.ByteArrayOutputStream

      `close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo`

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

      `flush, write`

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

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

- - ### Constructor Detail

    - #### ResizableByteArrayOutputStream

          public ResizableByteArrayOutputStream()

      Create a new `ResizableByteArrayOutputStream` with the default initial capacity of 128 bytes.

    - #### ResizableByteArrayOutputStream

          public ResizableByteArrayOutputStream(int initialCapacity)

      Create a new `ResizableByteArrayOutputStream` with the specified initial capacity.
      Parameters:
        `initialCapacity` - the initial buffer size in bytes

  - ### Method Detail

    - #### resize

          public void resize(int targetCapacity)

      Resize the internal buffer size to a specified capacity.
      Parameters:
        `targetCapacity` - the desired size of the buffer
      Throws:
        `IllegalArgumentException` - if the given capacity is smaller than the actual size of the content stored in the buffer already
      See Also:
        `ByteArrayOutputStream.size()`

    - #### grow

          public void grow(int additionalCapacity)

      Grow the internal buffer size.
      Parameters:
        `additionalCapacity` - the number of bytes to add to the current buffer size
      See Also:
        `ByteArrayOutputStream.size()`

    - #### capacity

          public int capacity()

      Return the current size of this stream's internal buffer.