public final class

ByteArrayBuilder

extends OutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ com.fasterxml.jackson.core.util.ByteArrayBuilder

Class Overview

Helper class that is similar to 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 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 java.io.ByteArrayOutputStream works, but somewhat more efficiently for many use cases.

Summary

Public Constructors
ByteArrayBuilder()
ByteArrayBuilder(BufferRecycler br)
ByteArrayBuilder(int firstBlockSize)
ByteArrayBuilder(BufferRecycler br, int firstBlockSize)
Public Methods
void append(int i)
void appendThreeBytes(int b24)
void appendTwoBytes(int b16)
void close()
byte[] completeAndCoalesce(int lastBlockLength)
Method that will complete "manual" output process, coalesce content (if necessary) and return results as a contiguous buffer.
byte[] finishCurrentSegment()
Method called when the current segment buffer is full; will append to current contents, allocate a new segment buffer and return it
void flush()
byte[] getCurrentSegment()
int getCurrentSegmentLength()
void release()
Clean up method to call to release all buffers this object may be using.
void reset()
byte[] resetAndGetFirstSegment()
Method called when starting "manual" output: will clear out current state and return the first segment buffer to fill
void setCurrentSegmentLength(int len)
byte[] toByteArray()
Method called when results are finalized and we can get the full aggregated result buffer to return to the caller
void write(int b)
void write(byte[] b, int off, int len)
void write(byte[] b)
[Expand]
Inherited Methods
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public Constructors

public ByteArrayBuilder ()

public ByteArrayBuilder (BufferRecycler br)

public ByteArrayBuilder (int firstBlockSize)

public ByteArrayBuilder (BufferRecycler br, int firstBlockSize)

Public Methods

public void append (int i)

public void appendThreeBytes (int b24)

public void appendTwoBytes (int b16)

public void close ()

public byte[] completeAndCoalesce (int lastBlockLength)

Method that will complete "manual" output process, coalesce content (if necessary) and return results as a contiguous buffer.

Parameters
lastBlockLength Amount of content in the current segment buffer.
Returns
  • Coalesced contents

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

public void flush ()

public byte[] getCurrentSegment ()

public int getCurrentSegmentLength ()

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)

public void reset ()

public byte[] resetAndGetFirstSegment ()

Method called when starting "manual" output: will clear out current state and return the first segment buffer to fill

public void setCurrentSegmentLength (int len)

public byte[] toByteArray ()

Method called when results are finalized and we can get the full aggregated result buffer to return to the caller

public void write (int b)

public void write (byte[] b, int off, int len)

public void write (byte[] b)