public class ResizableByteArrayOutputStream extends ByteArrayOutputStream
ByteArrayOutputStream
that:
grow(int)
and resize(int)
methods
to get more control over the the size of the internal bufferbuf, count
Constructor and Description |
---|
ResizableByteArrayOutputStream()
Create a new
ResizableByteArrayOutputStream
with the default initial capacity of 128 bytes. |
ResizableByteArrayOutputStream(int initialCapacity)
Create a new
ResizableByteArrayOutputStream
with the specified initial capacity. |
Modifier and Type | Method and Description |
---|---|
int |
capacity()
Return the current size of this stream's internal buffer.
|
void |
grow(int additionalCapacity)
Grow the internal buffer size.
|
void |
resize(int targetCapacity)
Resize the internal buffer size to a specified capacity.
|
close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo
flush, write
public ResizableByteArrayOutputStream()
ResizableByteArrayOutputStream
with the default initial capacity of 128 bytes.public ResizableByteArrayOutputStream(int initialCapacity)
ResizableByteArrayOutputStream
with the specified initial capacity.initialCapacity
- the initial buffer size in bytespublic void resize(int targetCapacity)
targetCapacity
- the desired size of the bufferIllegalArgumentException
- if the given capacity is smaller than
the actual size of the content stored in the buffer alreadyByteArrayOutputStream.size()
public void grow(int additionalCapacity)
additionalCapacity
- the number of bytes to add to the current buffer sizeByteArrayOutputStream.size()
public int capacity()