Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.core.util

public Class BufferRecycler

extends Object
implements RecyclerPool.WithPool<BufferRecycler>
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.core.util.RecyclerPool.WithPool
Imports
java.util.Objects, java.util.concurrent.atomic.AtomicReferenceArray

This is a small utility class, whose main functionality is to allow simple reuse of raw byte/char buffers. It is usually allocated through RecyclerPool (starting with 2.16): multiple pool implementations exists. The default pool implementation uses ThreadLocal combined with SoftReference. The end result is a low-overhead GC-cleanable recycling: hopefully ideal for use by stream readers.

Rewritten in 2.10 to be thread-safe (see [jackson-core#479] for details), to not rely on ThreadLocal access.
Rewritten in 2.16 to work with RecyclerPool abstraction.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
BufferRecycler.Gettable

Tag-on interface to allow various other types to expose BufferRecycler they are constructed with.

Field Summary

Modifier and TypeField and Description
protected final AtomicReferenceArray<byte[]>
protected final AtomicReferenceArray<char[]>
private RecyclerPool<BufferRecycler>
public static final int
BYTE_BASE64_CODEC_BUFFER

Buffer used for concatenating binary data that is either being encoded as base64 output, or decoded from base64 input.

private static final int[]
public static final int
BYTE_READ_IO_BUFFER

Buffer used for reading byte-based input.

public static final int
BYTE_WRITE_CONCAT_BUFFER

Buffer used for temporarily concatenating output; used for example when requesting output as byte array.

public static final int
BYTE_WRITE_ENCODING_BUFFER

Buffer used for temporarily storing encoded content; used for example by UTF-8 encoding writer

private static final int[]
public static final int
CHAR_CONCAT_BUFFER

Buffer used by generators; for byte-backed generators for buffering of String values to output (before encoding into UTF-8), and for char-backed generators as actual concatenation buffer.

public static final int
CHAR_NAME_COPY_BUFFER

For parsers, temporary buffer into which char[] for names is copied when requested as such; for WriterBasedGenerator used for buffering during writeString(Reader) operation (not commonly used).

public static final int
CHAR_TEXT_BUFFER

Used through TextBuffer: directly by parsers (to concatenate String values) and indirectly via com.fasterxml.jackson.core.io.SegmentedStringWriter when serializing (databind level ObjectMapper and ObjectWriter).

public static final int
CHAR_TOKEN_BUFFER

Buffer used as input buffer for tokenization for character-based parsers.

Constructor Summary

AccessConstructor and Description
public
BufferRecycler()

Default constructor used for creating instances of this default implementation.

protected
BufferRecycler(int
Number of byte[] buffers to allocate
bbCount
,
int
Number of char[] buffers to allocate
cbCount
)

Alternate constructor to be used by sub-classes, to allow customization of number of low-level buffers in use.

Method Summary

Modifier and TypeMethod and Description
public final byte[]

Returns:

Buffer allocated (possibly recycled)
allocByteBuffer
(int
One of READ_IO_BUFFER constants.
ix
)

public byte[]
allocByteBuffer(int ix, int minSize)

public final char[]
public char[]
allocCharBuffer(int ix, int minSize)

protected byte[]
balloc(int size)

protected int
protected char[]
calloc(int size)

protected int
public boolean

Returns:

True if this recycler is linked to pool and may be released with releaseToPool(); false if no linkage exists.
isLinkedWithPool
()

public void
releaseByteBuffer(int ix, byte[] buffer)

public void
releaseCharBuffer(int ix, char[] buffer)

public void
releaseToPool()

Implements com.fasterxml.jackson.core.util.RecyclerPool.WithPool.releaseToPool.

Method called when owner of this recycler no longer wishes use it; this should return it to pool passed via withPool() (if any).

public BufferRecycler
withPool(RecyclerPool<BufferRecycler>
Pool that "owns" pooled item
pool
)

Implements com.fasterxml.jackson.core.util.RecyclerPool.WithPool.withPool.

Method called by owner of this recycler instance, to provide reference to RecyclerPool into which instance is to be released (if any)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_byteBuffersback to summary
protected final AtomicReferenceArray<byte[]> _byteBuffers
_charBuffersback to summary
protected final AtomicReferenceArray<char[]> _charBuffers
_poolback to summary
private RecyclerPool<BufferRecycler> _pool
BYTE_BASE64_CODEC_BUFFERback to summary
public static final int BYTE_BASE64_CODEC_BUFFER

Buffer used for concatenating binary data that is either being encoded as base64 output, or decoded from base64 input.

Since
2.1
BYTE_BUFFER_LENGTHSback to summary
private static final int[] BYTE_BUFFER_LENGTHS
BYTE_READ_IO_BUFFERback to summary
public static final int BYTE_READ_IO_BUFFER

Buffer used for reading byte-based input.

BYTE_WRITE_CONCAT_BUFFERback to summary
public static final int BYTE_WRITE_CONCAT_BUFFER

Buffer used for temporarily concatenating output; used for example when requesting output as byte array.

BYTE_WRITE_ENCODING_BUFFERback to summary
public static final int BYTE_WRITE_ENCODING_BUFFER

Buffer used for temporarily storing encoded content; used for example by UTF-8 encoding writer

CHAR_BUFFER_LENGTHSback to summary
private static final int[] CHAR_BUFFER_LENGTHS
CHAR_CONCAT_BUFFERback to summary
public static final int CHAR_CONCAT_BUFFER

Buffer used by generators; for byte-backed generators for buffering of String values to output (before encoding into UTF-8), and for char-backed generators as actual concatenation buffer.

CHAR_NAME_COPY_BUFFERback to summary
public static final int CHAR_NAME_COPY_BUFFER

For parsers, temporary buffer into which char[] for names is copied when requested as such; for WriterBasedGenerator used for buffering during writeString(Reader) operation (not commonly used).

CHAR_TEXT_BUFFERback to summary
public static final int CHAR_TEXT_BUFFER

Used through TextBuffer: directly by parsers (to concatenate String values) and indirectly via com.fasterxml.jackson.core.io.SegmentedStringWriter when serializing (databind level ObjectMapper and ObjectWriter). In both cases used as segments (and not for whole value), but may result in retention of larger chunks for big content (long text values during parsing; bigger output documents for generation).

CHAR_TOKEN_BUFFERback to summary
public static final int CHAR_TOKEN_BUFFER

Buffer used as input buffer for tokenization for character-based parsers.

Constructor Detail

BufferRecyclerback to summary
public BufferRecycler()

Default constructor used for creating instances of this default implementation.

BufferRecyclerback to summary
protected BufferRecycler(int bbCount, int cbCount)

Alternate constructor to be used by sub-classes, to allow customization of number of low-level buffers in use.

Parameters
bbCount:int

Number of byte[] buffers to allocate

cbCount:int

Number of char[] buffers to allocate

Since
2.4

Method Detail

allocByteBufferback to summary
public final byte[] allocByteBuffer(int ix)
Parameters
ix:int

One of READ_IO_BUFFER constants.

Returns:byte[]

Buffer allocated (possibly recycled)

allocByteBufferback to summary
public byte[] allocByteBuffer(int ix, int minSize)
allocCharBufferback to summary
public final char[] allocCharBuffer(int ix)
allocCharBufferback to summary
public char[] allocCharBuffer(int ix, int minSize)
ballocback to summary
protected byte[] balloc(int size)
byteBufferLengthback to summary
protected int byteBufferLength(int ix)
callocback to summary
protected char[] calloc(int size)
charBufferLengthback to summary
protected int charBufferLength(int ix)
isLinkedWithPoolback to summary
public boolean isLinkedWithPool()
Returns:boolean

True if this recycler is linked to pool and may be released with releaseToPool(); false if no linkage exists.

Since
2.17
releaseByteBufferback to summary
public void releaseByteBuffer(int ix, byte[] buffer)
releaseCharBufferback to summary
public void releaseCharBuffer(int ix, char[] buffer)
releaseToPoolback to summary
public void releaseToPool()

Implements com.fasterxml.jackson.core.util.RecyclerPool.WithPool.releaseToPool.

Method called when owner of this recycler no longer wishes use it; this should return it to pool passed via withPool() (if any).

Annotations
@Override
Since
2.16
withPoolback to summary
public BufferRecycler withPool(RecyclerPool<BufferRecycler> pool)

Implements com.fasterxml.jackson.core.util.RecyclerPool.WithPool.withPool.

Method called by owner of this recycler instance, to provide reference to RecyclerPool into which instance is to be released (if any)

Parameters
pool:RecyclerPool<BufferRecycler>

Doc from com.fasterxml.jackson.core.util.RecyclerPool.WithPool.withPool.

Pool that "owns" pooled item

Returns:BufferRecycler

Doc from com.fasterxml.jackson.core.util.RecyclerPool.WithPool.withPool.

This item (for call chaining)

Annotations
@Override
Since
2.16
com.fasterxml.jackson.core.util back to summary

public Interface BufferRecycler.Gettable

Known Direct Implementers
com.fasterxml.jackson.core.util.ByteArrayBuilder, com.fasterxml.jackson.core.io.SegmentedStringWriter

Tag-on interface to allow various other types to expose BufferRecycler they are constructed with.
Since
2.17

Method Summary

Modifier and TypeMethod and Description
public BufferRecycler

Returns:

Buffer recycler instance object is configured with, if any; whether this can be null depends on type of object
bufferRecycler
()

Method Detail

bufferRecyclerback to summary
public BufferRecycler bufferRecycler()
Returns:BufferRecycler

Buffer recycler instance object is configured with, if any; whether this can be null depends on type of object