@NotThreadSafe public final class ExposedByteArrayOutputStream extends ByteArrayOutputStream
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.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DOUBLING_SIZE
Default buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%
|
buf, count
Constructor and Description |
---|
ExposedByteArrayOutputStream() |
ExposedByteArrayOutputStream(int size) |
ExposedByteArrayOutputStream(int size,
int maxDoublingSize)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
|
Modifier and Type | Method and Description |
---|---|
int |
getMaxDoublingSize()
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)
Gets the number of bytes to which the internal buffer should be resized.
|
byte[] |
getRawBuffer()
Gets the internal buffer array.
|
int |
size()
Overriden only to avoid unneeded synchronization
|
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
close, reset, toByteArray, toString, toString, toString, writeTo
flush, write
public static final int DEFAULT_DOUBLING_SIZE
public ExposedByteArrayOutputStream()
public ExposedByteArrayOutputStream(int size)
public ExposedByteArrayOutputStream(int size, int maxDoublingSize)
size
- the initial size.maxDoublingSize
- the buffer size, after which if more capacity is needed the buffer will grow by 25% rather
than 100%IllegalArgumentException
- if size is negative.public final byte[] getRawBuffer()
size()
to get the number of bytes of actual data.public final void write(byte[] b, int off, int len)
write
in class ByteArrayOutputStream
public final void write(int b)
write
in class ByteArrayOutputStream
public final int getMaxDoublingSize()
public final int getNewBufferSize(int curSize, int minNewSize)
curSize
- the current number of bytesminNewSize
- the minimum number of bytes requiredpublic final int size()
size
in class ByteArrayOutputStream
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.