Class JsonStringEncoder
java.lang.Object
tools.jackson.core.io.JsonStringEncoder
Helper class used for efficient encoding of JSON String values (including
JSON property 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]private static final char[]private static final JsonStringEncoderstatic final intstatic final intstatic final intstatic final intprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int_appendByte(int ch, int esc, ByteArrayBuilder bb, int ptr) private int_appendNamed(int esc, char[] qbuf) private int_appendNumeric(int value, char[] qbuf) private static int_convert(int p1, int p2) private static void_illegal(int c) static int_initialByteBufSize(int strLen) static int_initialCharBufSize(int strLen) private char[]_qbuf()byte[]encodeAsUTF8(CharSequence text) Will encode given String as UTF-8 (without any escaping) and return the resulting byte array.static JsonStringEncoderFactory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.char[]quoteAsCharArray(CharSequence input) Method that will escape text contents using JSON standard escaping, and return results as a character array.voidquoteAsString(CharSequence input, StringBuilder output) Method that will quote text contents using JSON standard quoting, and append results to a suppliedStringBuilder.byte[]quoteAsUTF8(CharSequence text) Method that will escape text contents using JSON standard escaping, encode resulting String as UTF-8 bytes and return results as a byte array.
-
Field Details
-
HC
private static final char[] HC -
HB
private static final byte[] HB -
SURR1_FIRST
private static final int SURR1_FIRST- See Also:
-
SURR1_LAST
private static final int SURR1_LAST- See Also:
-
SURR2_FIRST
private static final int SURR2_FIRST- See Also:
-
SURR2_LAST
private static final int SURR2_LAST- See Also:
-
MIN_CHAR_BUFFER_SIZE
public static final int MIN_CHAR_BUFFER_SIZE- See Also:
-
MAX_CHAR_BUFFER_SIZE
public static final int MAX_CHAR_BUFFER_SIZE- See Also:
-
MIN_BYTE_BUFFER_SIZE
public static final int MIN_BYTE_BUFFER_SIZE- See Also:
-
MAX_BYTE_BUFFER_SIZE
public static final int MAX_BYTE_BUFFER_SIZE- See Also:
-
instance
-
-
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.- Returns:
- Static stateless encoder instance
-
quoteAsCharArray
Method that will escape text contents using JSON standard escaping, and return results as a character array.- Parameters:
input- Value String to process- Returns:
- JSON-escaped String matching
input
-
quoteAsString
Method that will quote text contents using JSON standard quoting, and append results to a suppliedStringBuilder. Use this variant if you have e.g. aStringBuilderand want to avoid superfluous copying of it.- Parameters:
input- ValueCharSequenceto processoutput-StringBuilderto append escaped contents to
-
quoteAsUTF8
Method that will escape text contents using JSON standard escaping, encode resulting String as UTF-8 bytes and return results as a byte array.- Parameters:
text- Value String to process- Returns:
- UTF-8 encoded bytes of JSON-escaped
text
-
encodeAsUTF8
Will encode given String as UTF-8 (without any escaping) and return the resulting byte array.- Parameters:
text- Value String to process- Returns:
- UTF-8 encoded bytes of
text(without any escaping)
-
_qbuf
private char[] _qbuf() -
_appendNumeric
private int _appendNumeric(int value, char[] qbuf) -
_appendNamed
private int _appendNamed(int esc, char[] qbuf) -
_appendByte
-
_convert
private static int _convert(int p1, int p2) -
_illegal
private static void _illegal(int c) -
_initialCharBufSize
public static int _initialCharBufSize(int strLen) -
_initialByteBufSize
public static int _initialByteBufSize(int strLen)
-