public class PoolingByteArrayOutputStream
extends java.io.ByteArrayOutputStream
ByteArrayOutputStream that uses a pool of byte[] buffers instead
of always allocating them fresh, saving on heap churn.| Modifier and Type | Field and Description |
|---|---|
private static int |
DEFAULT_SIZE
If the
PoolingByteArrayOutputStream(ByteArrayPool) constructor is called, this is
the default size to which the underlying byte array is initialized. |
private ByteArrayPool |
mPool |
| Constructor and Description |
|---|
PoolingByteArrayOutputStream(ByteArrayPool pool)
Constructs a new PoolingByteArrayOutputStream with a default size.
|
PoolingByteArrayOutputStream(ByteArrayPool pool,
int size)
Constructs a new
ByteArrayOutputStream with a default size of size bytes. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
private void |
expand(int i)
Ensures there is enough space in the buffer for the given number of additional bytes.
|
void |
finalize() |
void |
write(byte[] buffer,
int offset,
int len) |
void |
write(int oneByte) |
private static final int DEFAULT_SIZE
PoolingByteArrayOutputStream(ByteArrayPool) constructor is called, this is
the default size to which the underlying byte array is initialized.private final ByteArrayPool mPool
public PoolingByteArrayOutputStream(ByteArrayPool pool)
public PoolingByteArrayOutputStream(ByteArrayPool pool, int size)
ByteArrayOutputStream with a default size of size bytes. If
more than size bytes are written to this instance, the underlying byte array will
expand.size - initial size for the underlying byte array. The value will be pinned to a default
minimum size.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.ByteArrayOutputStreamjava.io.IOExceptionpublic void finalize()
finalize in class java.lang.Objectprivate void expand(int i)
public void write(byte[] buffer,
int offset,
int len)
write in class java.io.ByteArrayOutputStreampublic void write(int oneByte)
write in class java.io.ByteArrayOutputStream