Package com.fasterxml.jackson.core.util
Class BufferRecycler
- java.lang.Object
-
- com.fasterxml.jackson.core.util.BufferRecycler
-
public class BufferRecycler extends java.lang.Object
This is a small utility class, whose main functionality is to allow simple reuse of raw byte/char buffers. It is usually used throughThreadLocal
member of the owning class pointing to instance of this class through aSoftReference
. 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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
BYTE_BASE64_CODEC_BUFFER
Buffer used for concatenating binary data that is either being encoded as base64 output, or decoded from base64 input.static int
BYTE_READ_IO_BUFFER
Buffer used for reading byte-based input.static int
BYTE_WRITE_CONCAT_BUFFER
Buffer used for temporarily concatenating output; used for example when requesting output as byte array.static int
BYTE_WRITE_ENCODING_BUFFER
Buffer used for temporarily storing encoded content; used for example by UTF-8 encoding writerstatic int
CHAR_CONCAT_BUFFER
Buffer used by generators; for byte-backed generators for buffering ofString
values to output (before encoding into UTF-8), and for char-backed generators as actual concatenation buffer.static int
CHAR_NAME_COPY_BUFFER
For parsers, temporary buffer into whichchar[]
for names is copied when requested as such; forWriterBasedGenerator
used for buffering duringwriteString(Reader)
operation (not commonly used).static int
CHAR_TEXT_BUFFER
Used throughTextBuffer
: directly by parsers (to concatenate String values) and indirectly viaSegmentedStringWriter
when serializing (databind levelObjectMapper
andObjectWriter
).static int
CHAR_TOKEN_BUFFER
Buffer used as input buffer for tokenization for character-based parsers.
-
Constructor Summary
Constructors Constructor Description BufferRecycler()
Default constructor used for creating instances of this default implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
allocByteBuffer(int ix)
byte[]
allocByteBuffer(int ix, int minSize)
char[]
allocCharBuffer(int ix)
char[]
allocCharBuffer(int ix, int minSize)
void
releaseByteBuffer(int ix, byte[] buffer)
void
releaseCharBuffer(int ix, char[] buffer)
-
-
-
Field Detail
-
BYTE_READ_IO_BUFFER
public static final int BYTE_READ_IO_BUFFER
Buffer used for reading byte-based input.- See Also:
- Constant Field Values
-
BYTE_WRITE_ENCODING_BUFFER
public static final int BYTE_WRITE_ENCODING_BUFFER
Buffer used for temporarily storing encoded content; used for example by UTF-8 encoding writer- See Also:
- Constant Field Values
-
BYTE_WRITE_CONCAT_BUFFER
public static final int BYTE_WRITE_CONCAT_BUFFER
Buffer used for temporarily concatenating output; used for example when requesting output as byte array.- See Also:
- Constant Field Values
-
BYTE_BASE64_CODEC_BUFFER
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
- See Also:
- Constant Field Values
-
CHAR_TOKEN_BUFFER
public static final int CHAR_TOKEN_BUFFER
Buffer used as input buffer for tokenization for character-based parsers.- See Also:
- Constant Field Values
-
CHAR_CONCAT_BUFFER
public static final int CHAR_CONCAT_BUFFER
Buffer used by generators; for byte-backed generators for buffering ofString
values to output (before encoding into UTF-8), and for char-backed generators as actual concatenation buffer.- See Also:
- Constant Field Values
-
CHAR_TEXT_BUFFER
public static final int CHAR_TEXT_BUFFER
Used throughTextBuffer
: directly by parsers (to concatenate String values) and indirectly viaSegmentedStringWriter
when serializing (databind levelObjectMapper
andObjectWriter
). 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).- See Also:
- Constant Field Values
-
CHAR_NAME_COPY_BUFFER
public static final int CHAR_NAME_COPY_BUFFER
For parsers, temporary buffer into whichchar[]
for names is copied when requested as such; forWriterBasedGenerator
used for buffering duringwriteString(Reader)
operation (not commonly used).- See Also:
- Constant Field Values
-
-
Method Detail
-
allocByteBuffer
public final byte[] allocByteBuffer(int ix)
- Parameters:
ix
- One ofREAD_IO_BUFFER
constants.- Returns:
- Buffer allocated (possibly recycled)
-
allocByteBuffer
public byte[] allocByteBuffer(int ix, int minSize)
-
releaseByteBuffer
public void releaseByteBuffer(int ix, byte[] buffer)
-
allocCharBuffer
public final char[] allocCharBuffer(int ix)
-
allocCharBuffer
public char[] allocCharBuffer(int ix, int minSize)
-
releaseCharBuffer
public void releaseCharBuffer(int ix, char[] buffer)
-
-