Package com.fasterxml.jackson.core.io
Class JsonStringEncoder
- java.lang.Object
-
- com.fasterxml.jackson.core.io.JsonStringEncoder
-
public final class JsonStringEncoder extends java.lang.Object
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.
-
-
Field Summary
Fields Modifier and Type Field Description private static byte[]
HB
private static char[]
HC
private static int
INITIAL_BYTE_BUFFER_SIZE
private static int
INITIAL_CHAR_BUFFER_SIZE
private static JsonStringEncoder
instance
private static int
SURR1_FIRST
private static int
SURR1_LAST
private static int
SURR2_FIRST
private static int
SURR2_LAST
-
Constructor Summary
Constructors Constructor Description JsonStringEncoder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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)
private char[]
_qbuf()
byte[]
encodeAsUTF8(java.lang.CharSequence text)
Overloaded variant ofencodeAsUTF8(String)
.byte[]
encodeAsUTF8(java.lang.String text)
Will encode given String as UTF-8 (without any quoting), return resulting byte array.static JsonStringEncoder
getInstance()
Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.char[]
quoteAsString(java.lang.CharSequence input)
Overloaded variant ofquoteAsString(String)
.void
quoteAsString(java.lang.CharSequence input, java.lang.StringBuilder output)
Method that will quote text contents using JSON standard quoting, and append results to a suppliedStringBuilder
.char[]
quoteAsString(java.lang.String input)
Method that will quote text contents using JSON standard quoting, and return results as a character arraybyte[]
quoteAsUTF8(java.lang.String text)
Will quote given JSON String value using standard quoting, encode results as UTF-8, and return result as a byte array.
-
-
-
Field Detail
-
HC
private static final char[] HC
-
HB
private static final byte[] HB
-
SURR1_FIRST
private static final int SURR1_FIRST
- See Also:
- Constant Field Values
-
SURR1_LAST
private static final int SURR1_LAST
- See Also:
- Constant Field Values
-
SURR2_FIRST
private static final int SURR2_FIRST
- See Also:
- Constant Field Values
-
SURR2_LAST
private static final int SURR2_LAST
- See Also:
- Constant Field Values
-
INITIAL_CHAR_BUFFER_SIZE
private static final int INITIAL_CHAR_BUFFER_SIZE
- See Also:
- Constant Field Values
-
INITIAL_BYTE_BUFFER_SIZE
private static final int INITIAL_BYTE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
instance
private static final JsonStringEncoder instance
-
-
Method Detail
-
getInstance
public static JsonStringEncoder getInstance()
Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.
-
quoteAsString
public char[] quoteAsString(java.lang.String input)
Method that will quote text contents using JSON standard quoting, and return results as a character array
-
quoteAsString
public char[] quoteAsString(java.lang.CharSequence input)
Overloaded variant ofquoteAsString(String)
.- Since:
- 2.10
-
quoteAsString
public void quoteAsString(java.lang.CharSequence input, java.lang.StringBuilder output)
Method that will quote text contents using JSON standard quoting, and append results to a suppliedStringBuilder
. Use this variant if you have e.g. aStringBuilder
and want to avoid superfluous copying of it.- Since:
- 2.8
-
quoteAsUTF8
public byte[] quoteAsUTF8(java.lang.String text)
Will quote given JSON String value using standard quoting, encode results as UTF-8, and return result as a byte array.
-
encodeAsUTF8
public byte[] encodeAsUTF8(java.lang.String text)
Will encode given String as UTF-8 (without any quoting), return resulting byte array.
-
encodeAsUTF8
public byte[] encodeAsUTF8(java.lang.CharSequence text)
Overloaded variant ofencodeAsUTF8(String)
.- Since:
- 2.11
-
_qbuf
private char[] _qbuf()
-
_appendNumeric
private int _appendNumeric(int value, char[] qbuf)
-
_appendNamed
private int _appendNamed(int esc, char[] qbuf)
-
_appendByte
private int _appendByte(int ch, int esc, ByteArrayBuilder bb, int ptr)
-
_convert
private static int _convert(int p1, int p2)
-
_illegal
private static void _illegal(int c)
-
-