public class CapacityByteArrayOutputStream extends OutputStream
ByteArrayOutputStream
behavior) by making the new slab size the size of the existing data.
When reusing a buffer it will adjust the slab size based on the previous data size (reset()
)Constructor and Description |
---|
CapacityByteArrayOutputStream(int initialSize) |
Modifier and Type | Method and Description |
---|---|
int |
getCapacity() |
long |
getCurrentIndex() |
String |
memUsageString(String prefix) |
void |
reset()
When re-using an instance with reset, it will adjust slab size based on previous data size.
|
void |
setByte(long index,
byte value)
Replace the byte stored at position index in this stream with value
|
long |
size() |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
void |
writeTo(OutputStream out)
Writes the complete contents of this buffer to the specified output stream argument.
|
close, flush, write
public CapacityByteArrayOutputStream(int initialSize)
initialSize
- the initialSize of the buffer (also slab size)public void write(int b)
write
in class OutputStream
public void write(byte[] b, int off, int len)
write
in class OutputStream
public void writeTo(OutputStream out) throws IOException
out.write(slab, 0, slab.length)
) will be called once per slab.out
- the output stream to which to write the data.IOException
- if an I/O error occurs.public int getCapacity()
public void reset()
public long size()
public long getCurrentIndex()
setByte(long, byte)
in order to change itpublic void setByte(long index, byte value)
index
- which byte to replacevalue
- the value to replace it withCopyright © 2015. All rights reserved.