java.io.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 reallocations, copying), as well API
not based on java.io.OutputStream . In short, a very much
specialized builder object.
Also implements OutputStream to allow
efficient aggregation of output content as a byte array, similar
to how java. works, but somewhat more
efficiently for many use cases.
Note
maximum size limited to Java Array maximum, 2 gigabytes: this because usage pattern is to collect content for a `byte[]` and so although theoretically this builder can aggregate more content it will not be usable as things are. Behavior may be improved if we solve the access problem.
| Modifier and Type | Field and Description |
|---|---|
| private final BufferRecycler | |
| private byte[] | |
| private int | |
| private final LinkedList | |
| private int | |
| pack-priv static final int | |
| private static final int | |
| private static final int | |
| public static final byte[] |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public BufferRecycler | |
| public void | close()
Overrides java. Implements java. Closes this output stream and releases any system resources associated with this stream. |
| public byte[] | Returns: Coalesced contentsAmount of content in the current segment
buffer. lastBlockLength)Method that will complete "manual" output process, coalesce content (if necessary) and return results as a contiguous buffer. |
| public byte[] | Returns: Segment to use for writingMethod called when the current segment buffer is full; will append to current contents, allocate a new segment buffer and return it |
| public void | flush()
Overrides java. Implements java. Flushes this output stream and forces any buffered output bytes to be written out. |
| public static ByteArrayBuilder | |
| public byte[] | Returns: Content in byte arrayMethod functionally same as calling: byte[] bytes = toByteArray(); release(); return bytes; |
| public byte[] | |
| public int | |
| public void | |
| public void | |
| public byte[] | Returns: Segment to use for writingMethod called when starting "manual" output: will clear out current state and return the first segment buffer to fill |
| public void | |
| public int | |
| public byte[] | Returns: Aggregated contents as abyte[]Method called when results are finalized and we can get the full aggregated result buffer to return to the caller |
| public void | write(byte[]
the data. b)Overrides java. Writes |
| public void | write(byte[]
the data. b, int the start offset in the data. off, int the number of bytes to write. len)Overrides java. Writes |
| public void | write(int
the b)byte.Implements abstract java. Writes the specified byte to this output stream. |
| _bufferRecycler | back to summary |
|---|---|
| private final BufferRecycler _bufferRecycler | |
| _currBlock | back to summary |
|---|---|
| private byte[] _currBlock | |
| _currBlockPtr | back to summary |
|---|---|
| private int _currBlockPtr | |
| _pastBlocks | back to summary |
|---|---|
| private final LinkedList<byte[]> _pastBlocks | |
| _pastLen | back to summary |
|---|---|
| private int _pastLen | |
| DEFAULT_BLOCK_ARRAY_SIZE | back to summary |
|---|---|
| pack-priv static final int DEFAULT_BLOCK_ARRAY_SIZE | |
| INITIAL_BLOCK_SIZE | back to summary |
|---|---|
| private static final int INITIAL_BLOCK_SIZE | |
| MAX_BLOCK_SIZE | back to summary |
|---|---|
| private static final int MAX_BLOCK_SIZE | |
| NO_BYTES | back to summary |
|---|---|
| public static final byte[] NO_BYTES | |
| ByteArrayBuilder | back to summary |
|---|---|
| public ByteArrayBuilder() | |
| ByteArrayBuilder | back to summary |
|---|---|
| public ByteArrayBuilder(BufferRecycler br) | |
| ByteArrayBuilder | back to summary |
|---|---|
| public ByteArrayBuilder(int firstBlockSize) | |
| ByteArrayBuilder | back to summary |
|---|---|
| public ByteArrayBuilder(BufferRecycler br, int firstBlockSize) | |
| ByteArrayBuilder | back to summary |
|---|---|
| private ByteArrayBuilder(BufferRecycler br, byte[] initialBlock, int initialLen) | |
| _allocMore | back to summary |
|---|---|
| private void _allocMore() | |
| append | back to summary |
|---|---|
| public void append(int i) | |
| appendFourBytes | back to summary |
|---|---|
| public void appendFourBytes(int b32) | |
| appendThreeBytes | back to summary |
|---|---|
| public void appendThreeBytes(int b24) | |
| appendTwoBytes | back to summary |
|---|---|
| public void appendTwoBytes(int b16) | |
| bufferRecycler | back to summary |
|---|---|
| public BufferRecycler bufferRecycler() Implements com.
| |
| close | back to summary |
|---|---|
| public void close() Overrides java. Implements java. Doc from java. Closes this output stream and releases any system resources
associated with this stream. The general contract of
| |
| completeAndCoalesce | back to summary |
|---|---|
| public byte[] completeAndCoalesce(int lastBlockLength) Method that will complete "manual" output process, coalesce content (if necessary) and return results as a contiguous buffer.
| |
| finishCurrentSegment | back to summary |
|---|---|
| public byte[] finishCurrentSegment() Method called when the current segment buffer is full; will append to current contents, allocate a new segment buffer and return it
| |
| flush | back to summary |
|---|---|
| public void flush() Overrides java. Implements java. Doc from java. Flushes this output stream and forces any buffered output bytes
to be written out. The general contract of If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
| |
| fromInitial | back to summary |
|---|---|
| public static ByteArrayBuilder fromInitial(byte[] initialBlock, int length) | |
| getClearAndRelease | back to summary |
|---|---|
| public byte[] getClearAndRelease() Method functionally same as calling: byte[] bytes = toByteArray(); release(); return bytes;that is; aggregates output contained in the builder (if any), clear state; returns buffer(s) to BufferRecycler configured,
if any, and returns output to caller.
| |
| getCurrentSegment | back to summary |
|---|---|
| public byte[] getCurrentSegment() | |
| getCurrentSegmentLength | back to summary |
|---|---|
| public int getCurrentSegmentLength() | |
| release | back to summary |
|---|---|
| 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). | |
| reset | back to summary |
|---|---|
| public void reset() | |
| resetAndGetFirstSegment | back to summary |
|---|---|
| public byte[] resetAndGetFirstSegment() Method called when starting "manual" output: will clear out current state and return the first segment buffer to fill
| |
| setCurrentSegmentLength | back to summary |
|---|---|
| public void setCurrentSegmentLength(int len) | |
| size | back to summary |
|---|---|
public int size()
| |
| toByteArray | back to summary |
|---|---|
| public byte[] toByteArray() Method called when results are finalized and we can get the full aggregated result buffer to return to the caller
| |
| write | back to summary |
|---|---|
| public void write(byte[] b) Overrides java. Doc from java. Writes
| |
| write | back to summary |
|---|---|
| public void write(byte[] b, int off, int len) Overrides java. Doc from java. Writes
If
If
| |
| write | back to summary |
|---|---|
| public void write(int b) Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |