Class LimitedByteArrayOutputStream

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
com.activeviam.io.LimitedByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
CompressionOutputStream

public class LimitedByteArrayOutputStream extends ByteArrayOutputStream
A ByteArrayOutputStream that throws an ActiveViamRuntimeException when reaching the selected size limit in order to avoid OOM Errors when the underlying byte buffer overflows.

The underlying byte array must be strictly smaller than the limit defining this output stream.

Author:
ActiveViam
  • Field Details

    • SOFT_MAX_ARRAY_LENGTH

      public static final int SOFT_MAX_ARRAY_LENGTH
      A soft maximum array length imposed by array growth computations. Some JVMs (such as HotSpot) have an implementation limit that will cause

      OutOfMemoryError("Requested array size exceeds VM limit")

      to be thrown if a request is made to allocate an array of some length near Integer.MAX_VALUE, even if there is sufficient heap available. The actual limit might depend on some JVM implementation-specific characteristics such as the object header size. The soft maximum value is chosen conservatively to be smaller than any JVM implementation limit that is likely to be encountered.

      See Also:
    • MB

      public static final long MB
      One megabyte.
      See Also:
  • Constructor Details

    • LimitedByteArrayOutputStream

      public LimitedByteArrayOutputStream(int initialSize, int limit)
      Constructor.
      Parameters:
      initialSize - the initial size of the byte array. Must be strictly smaller than the limit.
      limit - the selected maximum size of the underlying byte array
    • LimitedByteArrayOutputStream

      public LimitedByteArrayOutputStream(int limit)
      Constructor.
      Parameters:
      limit - the selected maximum size of the underlying byte array. Must be strictly greater than the default byte array size.
  • Method Details