Package org.infinispan.commons.io
Class ExposedByteArrayOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.infinispan.commons.io.ExposedByteArrayOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
@NotThreadSafe
@Deprecated(forRemoval=true)
public final class ExposedByteArrayOutputStream
extends ByteArrayOutputStream
Deprecated, for removal: This API element is subject to removal in a future version.
Extends ByteArrayOutputStream, but exposes the internal buffer. Using this, callers don't need to call toByteArray()
which copies the internal buffer.
Also overrides the superclass' behavior of always doubling the size of the internal buffer any time more capacity is needed. This class doubles the size until the internal buffer reaches a configurable max size (default is 4MB), after which it begins growing the buffer in 25% increments. This is intended to help prevent an OutOfMemoryError during a resize of a large buffer.
A version of this class was originally created by Bela Ban as part of the JGroups library.
This class is not threadsafe as it will not support concurrent readers and writers.- Since:
- 4.0
- Author:
- Brian Stansberry
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Deprecated, for removal: This API element is subject to removal in a future version.Default buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%Fields inherited from class java.io.ByteArrayOutputStream
buf, count
-
Constructor Summary
ConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.ExposedByteArrayOutputStream
(int size) Deprecated, for removal: This API element is subject to removal in a future version.ExposedByteArrayOutputStream
(int size, int maxDoublingSize) Deprecated, for removal: This API element is subject to removal in a future version.Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Deprecated, for removal: This API element is subject to removal in a future version.Gets the highest internal buffer size after which if more capacity is needed the buffer will grow in 25% increments rather than 100%.int
getNewBufferSize
(int curSize, int minNewSize) Deprecated, for removal: This API element is subject to removal in a future version.Gets the number of bytes to which the internal buffer should be resized.byte[]
Deprecated, for removal: This API element is subject to removal in a future version.Gets the internal buffer array.int
size()
Deprecated, for removal: This API element is subject to removal in a future version.Overriden only to avoid unneeded synchronizationvoid
write
(byte[] b, int off, int len) Deprecated, for removal: This API element is subject to removal in a future version.void
write
(int b) Deprecated, for removal: This API element is subject to removal in a future version.Methods inherited from class java.io.ByteArrayOutputStream
close, reset, toByteArray, toString, toString, toString, toString, writeBytes, writeTo
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
DEFAULT_DOUBLING_SIZE
public static final int DEFAULT_DOUBLING_SIZEDeprecated, for removal: This API element is subject to removal in a future version.Default buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%- See Also:
-
-
Constructor Details
-
ExposedByteArrayOutputStream
public ExposedByteArrayOutputStream()Deprecated, for removal: This API element is subject to removal in a future version. -
ExposedByteArrayOutputStream
public ExposedByteArrayOutputStream(int size) Deprecated, for removal: This API element is subject to removal in a future version. -
ExposedByteArrayOutputStream
public ExposedByteArrayOutputStream(int size, int maxDoublingSize) Deprecated, for removal: This API element is subject to removal in a future version.Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.- Parameters:
size
- the initial size.maxDoublingSize
- the buffer size, after which if more capacity is needed the buffer will grow by 25% rather than 100%- Throws:
IllegalArgumentException
- if size is negative.
-
-
Method Details
-
getRawBuffer
public byte[] getRawBuffer()Deprecated, for removal: This API element is subject to removal in a future version.Gets the internal buffer array. Note that the length of this array will almost certainly be longer than the data written to it; callsize()
to get the number of bytes of actual data. -
write
public void write(byte[] b, int off, int len) Deprecated, for removal: This API element is subject to removal in a future version.- Overrides:
write
in classByteArrayOutputStream
-
write
public void write(int b) Deprecated, for removal: This API element is subject to removal in a future version.- Overrides:
write
in classByteArrayOutputStream
-
getMaxDoublingSize
public final int getMaxDoublingSize()Deprecated, for removal: This API element is subject to removal in a future version.Gets the highest internal buffer size after which if more capacity is needed the buffer will grow in 25% increments rather than 100%. -
getNewBufferSize
public int getNewBufferSize(int curSize, int minNewSize) Deprecated, for removal: This API element is subject to removal in a future version.Gets the number of bytes to which the internal buffer should be resized.- Parameters:
curSize
- the current number of bytesminNewSize
- the minimum number of bytes required- Returns:
- the size to which the internal buffer should be resized
-
size
public int size()Deprecated, for removal: This API element is subject to removal in a future version.Overriden only to avoid unneeded synchronization- Overrides:
size
in classByteArrayOutputStream
-
LazyByteArrayOutputStream
instead.