Package org.codehaus.jackson.io
Class JsonStringEncoder
java.lang.Object
org.codehaus.jackson.io.JsonStringEncoder
Helper class used for efficient encoding of JSON String values (including
JSON field names) into Strings or UTF-8 byte arrays.
Note that methods in here are somewhat optimized, but not ridiculously so. Reason is that conversion method results are expected to be cached so that these methods will not be hot spots during normal operation.
- Since:
- 1.6
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteArrayBuilder
Lazily-constructed builder used for UTF-8 encoding of text values (quoted and unquoted)protected final char[]
Temporary buffer used for composing quote/escape sequencesprotected TextBuffer
Lazily constructed text buffer used to produce JSON encoded Strings as characters (without UTF-8 encoding)protected static final ThreadLocal
<SoftReference<JsonStringEncoder>> ThisThreadLocal
contains aSoftReference
to aBufferRecycler
used to provide a low-cost buffer recycling between reader and writer instances. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
encodeAsUTF8
(String text) Will encode given String as UTF-8 (without any quoting), return resulting byte array.static JsonStringEncoder
Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.char[]
quoteAsString
(String input) Method that will quote text contents using JSON standard quoting, and return results as a character arraybyte[]
quoteAsUTF8
(String text) Will quote given JSON String value using standard quoting, encode results as UTF-8, and return result as a byte array.
-
Field Details
-
_threadEncoder
ThisThreadLocal
contains aSoftReference
to aBufferRecycler
used to provide a low-cost buffer recycling between reader and writer instances. -
_textBuffer
Lazily constructed text buffer used to produce JSON encoded Strings as characters (without UTF-8 encoding) -
_byteBuilder
Lazily-constructed builder used for UTF-8 encoding of text values (quoted and unquoted) -
_quoteBuffer
protected final char[] _quoteBufferTemporary buffer used for composing quote/escape sequences
-
-
Constructor Details
-
JsonStringEncoder
public JsonStringEncoder()
-
-
Method Details
-
getInstance
Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one. -
quoteAsString
Method that will quote text contents using JSON standard quoting, and return results as a character array -
quoteAsUTF8
Will quote given JSON String value using standard quoting, encode results as UTF-8, and return result as a byte array. -
encodeAsUTF8
Will encode given String as UTF-8 (without any quoting), return resulting byte array.
-