public class WritableByteArray extends ByteArrayOutputStream
This saves memory over creating a new byte[] and ByteArrayOutputStream each time data is written.
Typical usage is something like the following:
WritableByteArray buffer = new WritableByteArray(); while (... loop condition ...) { buffer.reset(); ... write to buffer ... byte[] data = buffer.getData(); int dataLength = buffer.getLength(); ... write data to its ultimate destination ... }
buf, count
Constructor and Description |
---|
WritableByteArray() |
WritableByteArray(byte[] buf) |
WritableByteArray(int size) |
Modifier and Type | Method and Description |
---|---|
byte[] |
getData()
Returns the current contents of the buffer.
|
int |
getLength()
Returns the length of the valid data currently in the buffer
|
close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo
flush, write
public WritableByteArray()
public WritableByteArray(int size)
public WritableByteArray(byte[] buf)
public byte[] getData()
getLength()
.public int getLength()
Copyright © 2007-2012 The Apache Software Foundation