org.codehaus.jackson.util
Class ByteArrayBuilder
java.lang.Object
java.io.OutputStream
org.codehaus.jackson.util.ByteArrayBuilder
- All Implemented Interfaces:
- Closeable, Flushable
public final class ByteArrayBuilder
- extends OutputStream
Helper class that is similar to ByteArrayOutputStream
in usage, but more geared to Jackson use cases internally.
Specific changes include segment storage (no need to have linear
backing buffer, can avoid reallocs, copying), as well API
not based on OutputStream
. In short, a very much
specialized builder object.
Since version 1.5, also implements OutputStream
to allow
efficient aggregation of output content as a byte array, similar
to how ByteArrayOutputStream
works, but somewhat more
efficiently for many use cases.
Method Summary |
void |
append(int i)
|
void |
appendThreeBytes(int b24)
|
void |
appendTwoBytes(int b16)
|
void |
close()
|
void |
flush()
|
void |
release()
Clean up method to call to release all buffers this object may be
using. |
void |
reset()
|
byte[] |
toByteArray()
Method called when results are finalized and we can get the
full aggregated result buffer to return to the caller |
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ByteArrayBuilder
public ByteArrayBuilder()
ByteArrayBuilder
public ByteArrayBuilder(BufferRecycler br)
ByteArrayBuilder
public ByteArrayBuilder(int firstBlockSize)
ByteArrayBuilder
public ByteArrayBuilder(BufferRecycler br,
int firstBlockSize)
reset
public void reset()
release
public void release()
- Clean up method to call to release all buffers this object may be
using. After calling the method, no other accessors can be used (and
attempt to do so may result in an exception)
append
public void append(int i)
appendTwoBytes
public void appendTwoBytes(int b16)
appendThreeBytes
public void appendThreeBytes(int b24)
toByteArray
public byte[] toByteArray()
- Method called when results are finalized and we can get the
full aggregated result buffer to return to the caller
write
public void write(byte[] b)
- Overrides:
write
in class OutputStream
write
public void write(byte[] b,
int off,
int len)
- Overrides:
write
in class OutputStream
write
public void write(int b)
throws IOException
- Specified by:
write
in class OutputStream
- Throws:
IOException
close
public void close()
- Specified by:
close
in interface Closeable
- Overrides:
close
in class OutputStream
flush
public void flush()
- Specified by:
flush
in interface Flushable
- Overrides:
flush
in class OutputStream