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
public class LimitedByteArrayOutputStream extends ByteArrayOutputStream
AByteArrayOutputStreamthat throws anActiveViamRuntimeExceptionwhen reaching the selected size limit in order to avoidOOM Errorswhen the underlying byte buffer overflows.The underlying byte array must be strictly smaller than the limit defining this output stream.
- Author:
- ActiveViam
-
-
Field Summary
Fields Modifier and Type Field Description static longMBOne megabyte.static intSOFT_MAX_ARRAY_LENGTHA soft maximum array length imposed by array growth computations.
-
Constructor Summary
Constructors Constructor Description LimitedByteArrayOutputStream(int limit)Constructor.LimitedByteArrayOutputStream(int initialSize, int limit)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int byteToWrite)-
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, toString, writeBytes, writeTo
-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream
-
-
-
-
Field Detail
-
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 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:
- Constant Field Values
-
MB
public static final long MB
One megabyte.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
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
-
-