Package com.activeviam.io
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
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final longOne megabyte.static final intA soft maximum array length imposed by array growth computations. -
Constructor Summary
ConstructorsConstructorDescriptionLimitedByteArrayOutputStream(int limit) Constructor.LimitedByteArrayOutputStream(int initialSize, int limit) Constructor. -
Method Summary
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, writeBytes, writeToMethods inherited from class java.io.OutputStream
flush, nullOutputStream
-
Field Details
-
SOFT_MAX_ARRAY_LENGTH
public static final int SOFT_MAX_ARRAY_LENGTHA soft maximum array length imposed by array growth computations. Some JVMs (such as HotSpot) have an implementation limit that will causeOutOfMemoryError("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 MBOne 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
-
write
public void write(int byteToWrite) - Overrides:
writein classByteArrayOutputStream
-
write
public void write(byte[] b) - Overrides:
writein classOutputStream
-
write
public void write(byte[] b, int off, int len) - Overrides:
writein classByteArrayOutputStream
-