Class BigByteArrayOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BigByteArrayOutputStream extends ReversibleOutputStream
This class represents a ByteArrayOutputStream that can hold a large amount of byte data. It is designed to overcome the limitations of the standard ByteArrayOutputStream, which has a fixed internal byte array and can run into out of memory errors when trying to write a large amount of data.

The BigByteArrayOutputStream works by using an ArrayList of ByteArrayOutputStreams to store the byte data. When the current ByteArrayOutputStream fills up, a new one is created with the maximum array size (Integer.MAX_VALUE - 8) as its initial capacity and added to the list. Writing data to the stream involves writing to the current active ByteArrayOutputStream. When the stream is cleared, all the internal ByteArrayOutputStreams are cleared and a new one is added to the list.

  • Field Details

    • ARRAY_SIZE_LIMIT

      public static final int ARRAY_SIZE_LIMIT
      The maximum size limit for an array. This is no limit to the amount of bytes BigByteArrayOutputStream can consume.
      See Also:
  • Constructor Details

    • BigByteArrayOutputStream

      public BigByteArrayOutputStream()
      Initializes a new instance of the BigByteArrayOutputStream class with default buffer size.
    • BigByteArrayOutputStream

      public BigByteArrayOutputStream(int bufferSize)
      Initializes a new instance of the BigByteArrayOutputStream class with buffer size.
      Parameters:
      bufferSize - initial guaranteed buffer size
    • BigByteArrayOutputStream

      public BigByteArrayOutputStream(long bufferSize)
      Initializes a new instance of the BigByteArrayOutputStream class with buffer size.
      Parameters:
      bufferSize - initial guaranteed buffer size
  • Method Details