Package com.fasterxml.jackson.core.io
Class JsonStringEncoder
- java.lang.Object
-
- com.fasterxml.jackson.core.io.JsonStringEncoder
-
public final class JsonStringEncoder extends java.lang.ObjectHelper 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[]HBprivate static char[]HCprivate static JsonStringEncoderinstance(package private) static intMAX_BYTE_BUFFER_SIZE(package private) static intMAX_CHAR_BUFFER_SIZE(package private) static intMIN_BYTE_BUFFER_SIZE(package private) static intMIN_CHAR_BUFFER_SIZEprivate static intSURR1_FIRSTprivate static intSURR1_LASTprivate static intSURR2_FIRSTprivate static intSURR2_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)(package private) static int_initialByteBufSize(int strLen)(package private) static int_initialCharBufSize(int strLen)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 escaping) and return the resulting byte array.static JsonStringEncodergetInstance()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).voidquoteAsString(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 escape text contents using JSON standard escaping, and return results as a character array.byte[]quoteAsUTF8(java.lang.String 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 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
-
MIN_CHAR_BUFFER_SIZE
static final int MIN_CHAR_BUFFER_SIZE
- See Also:
- Constant Field Values
-
MAX_CHAR_BUFFER_SIZE
static final int MAX_CHAR_BUFFER_SIZE
- See Also:
- Constant Field Values
-
MIN_BYTE_BUFFER_SIZE
static final int MIN_BYTE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
MAX_BYTE_BUFFER_SIZE
static final int MAX_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.- Returns:
- Static stateless encoder instance
-
quoteAsString
public char[] quoteAsString(java.lang.String input)
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
public char[] quoteAsString(java.lang.CharSequence input)
Overloaded variant ofquoteAsString(String).- Parameters:
input- ValueCharSequenceto process- Returns:
- JSON-escaped String matching
input - 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. aStringBuilderand want to avoid superfluous copying of it.- Parameters:
input- ValueCharSequenceto processoutput-StringBuilderto append escaped contents to- Since:
- 2.8
-
quoteAsUTF8
public byte[] quoteAsUTF8(java.lang.String 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.- Parameters:
text- ValueStringto process- Returns:
- UTF-8 encoded bytes of JSON-escaped
text
-
encodeAsUTF8
public byte[] encodeAsUTF8(java.lang.String text)
Will encode given String as UTF-8 (without any escaping) and return the resulting byte array.- Parameters:
text- ValueStringto process- Returns:
- UTF-8 encoded bytes of
text(without any escaping)
-
encodeAsUTF8
public byte[] encodeAsUTF8(java.lang.CharSequence text)
Overloaded variant ofencodeAsUTF8(String).- Parameters:
text- ValueCharSequenceto process- Returns:
- UTF-8 encoded bytes of
text(without any escaping) - 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)
-
_initialCharBufSize
static int _initialCharBufSize(int strLen)
-
_initialByteBufSize
static int _initialByteBufSize(int strLen)
-
-