Package com.fasterxml.jackson.core.util
Class BufferRecyclers
- java.lang.Object
-
- com.fasterxml.jackson.core.util.BufferRecyclers
-
public class BufferRecyclers extends java.lang.Object
Helper entity used to control access to simple buffer recyling scheme used for some encoding, decoding tasks.- Since:
- 2.9.2
- See Also:
BufferRecycler
,JsonStringEncoder
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<JsonStringEncoder>>
_encoderRef
ThisThreadLocal
contains aSoftReference
to aBufferRecycler
used to provide a low-cost buffer recycling between reader and writer instances.protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>>
_recyclerRef
ThisThreadLocal
contains aSoftReference
to aBufferRecycler
used to provide a low-cost buffer recycling between reader and writer instances.static java.lang.String
SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS
System property that is checked to see if recycled buffers (seeBufferRecycler
) should be tracked, for purpose of forcing release of all such buffers, typically during major classloading.
-
Constructor Summary
Constructors Constructor Description BufferRecyclers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
encodeAsUTF8(java.lang.String text)
Helper method for encoding given String as UTF-8 encodedstatic BufferRecycler
getBufferRecycler()
Main accessor to call for accessing possibly recycledBufferRecycler
instance.static JsonStringEncoder
getJsonStringEncoder()
static void
quoteAsJsonText(java.lang.CharSequence input, java.lang.StringBuilder output)
static char[]
quoteAsJsonText(java.lang.String rawText)
static byte[]
quoteAsJsonUTF8(java.lang.String rawText)
static int
releaseBuffers()
Specialized method that will release all recycledBufferRecycler
if (and only if) recycler tracking has been enabled (seeSYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS
).
-
-
-
Field Detail
-
SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS
public static final java.lang.String SYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS
System property that is checked to see if recycled buffers (seeBufferRecycler
) should be tracked, for purpose of forcing release of all such buffers, typically during major classloading.- Since:
- 2.9.6
- See Also:
- Constant Field Values
-
_recyclerRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<BufferRecycler>> _recyclerRef
ThisThreadLocal
contains aSoftReference
to aBufferRecycler
used to provide a low-cost buffer recycling between reader and writer instances.
-
_encoderRef
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<JsonStringEncoder>> _encoderRef
ThisThreadLocal
contains aSoftReference
to aBufferRecycler
used to provide a low-cost buffer recycling between reader and writer instances.
-
-
Method Detail
-
getBufferRecycler
public static BufferRecycler getBufferRecycler()
Main accessor to call for accessing possibly recycledBufferRecycler
instance.
-
releaseBuffers
public static int releaseBuffers()
Specialized method that will release all recycledBufferRecycler
if (and only if) recycler tracking has been enabled (seeSYSTEM_PROPERTY_TRACK_REUSABLE_BUFFERS
). This method is usually called on shutdown of the container like Application Server to ensure that no references are reachable viaThreadLocal
s as this may cause unintentional retention of sizable amounts of memory. It may also be called regularly if GC for some reason does not clear upSoftReference
s aggressively enough.- Returns:
- Number of buffers released, if tracking enabled (zero or more); -1 if tracking not enabled.
- Since:
- 2.9.6
-
getJsonStringEncoder
public static JsonStringEncoder getJsonStringEncoder()
-
encodeAsUTF8
public static byte[] encodeAsUTF8(java.lang.String text)
Helper method for encoding given String as UTF-8 encoded- Since:
- 2.9.4
-
quoteAsJsonText
public static char[] quoteAsJsonText(java.lang.String rawText)
- Since:
- 2.9.4
-
quoteAsJsonText
public static void quoteAsJsonText(java.lang.CharSequence input, java.lang.StringBuilder output)
- Since:
- 2.9.4
-
quoteAsJsonUTF8
public static byte[] quoteAsJsonUTF8(java.lang.String rawText)
- Since:
- 2.9.4
-
-