Top Description Fields Constructors Methods
tools.jackson.core.io

public Class JsonStringEncoder

extends Object
Class Inheritance
Imports
java.util.Arrays, tools.jackson.core.util.ByteArrayBuilder, .TextBuffer

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

Modifier and TypeField and Description
private static final byte[]
private static final char[]
private static final JsonStringEncoder
public static final int
public static final int
public static final int
public static final int
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and 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)

public static int
_initialByteBufSize(int strLen)

public static int
_initialCharBufSize(int strLen)

private char[]
public byte[]

Returns:

UTF-8 encoded bytes of text (without any escaping)
encodeAsUTF8
(CharSequence
Value String to process
text
)

Will encode given String as UTF-8 (without any escaping) and return the resulting byte array.

public static JsonStringEncoder

Returns:

Static stateless encoder instance
getInstance
()

Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.

public char[]

Returns:

JSON-escaped String matching input
quoteAsCharArray
(CharSequence
Value String to process
input
)

Method that will escape text contents using JSON standard escaping, and return results as a character array.

public void
quoteAsString(CharSequence
Value CharSequence to process
input
,
StringBuilder
StringBuilder to append escaped contents to
output
)

Method that will quote text contents using JSON standard quoting, and append results to a supplied StringBuilder.

public byte[]

Returns:

UTF-8 encoded bytes of JSON-escaped text
quoteAsUTF8
(CharSequence
Value String to process
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HBback to summary
private static final byte[] HB
HCback to summary
private static final char[] HC
instanceback to summary
private static final JsonStringEncoder instance
MAX_BYTE_BUFFER_SIZEback to summary
public static final int MAX_BYTE_BUFFER_SIZE
MAX_CHAR_BUFFER_SIZEback to summary
public static final int MAX_CHAR_BUFFER_SIZE
MIN_BYTE_BUFFER_SIZEback to summary
public static final int MIN_BYTE_BUFFER_SIZE
MIN_CHAR_BUFFER_SIZEback to summary
public static final int MIN_CHAR_BUFFER_SIZE
SURR1_FIRSTback to summary
private static final int SURR1_FIRST
SURR1_LASTback to summary
private static final int SURR1_LAST
SURR2_FIRSTback to summary
private static final int SURR2_FIRST
SURR2_LASTback to summary
private static final int SURR2_LAST

Constructor Detail

JsonStringEncoderback to summary
public JsonStringEncoder()

Method Detail

_appendByteback to summary
private int _appendByte(int ch, int esc, ByteArrayBuilder bb, int ptr)
_appendNamedback to summary
private int _appendNamed(int esc, char[] qbuf)
_appendNumericback to summary
private int _appendNumeric(int value, char[] qbuf)
_convertback to summary
private static int _convert(int p1, int p2)
_illegalback to summary
private static void _illegal(int c)
_initialByteBufSizeback to summary
public static int _initialByteBufSize(int strLen)
_initialCharBufSizeback to summary
public static int _initialCharBufSize(int strLen)
_qbufback to summary
private char[] _qbuf()
encodeAsUTF8back to summary
public byte[] encodeAsUTF8(CharSequence text)

Will encode given String as UTF-8 (without any escaping) and return the resulting byte array.

Parameters
text:CharSequence

Value String to process

Returns:byte[]

UTF-8 encoded bytes of text (without any escaping)

Annotations
@SuppressWarnings:resource
getInstanceback to summary
public static JsonStringEncoder getInstance()

Factory method for getting an instance; this is either recycled per-thread instance, or a newly constructed one.

Returns:JsonStringEncoder

Static stateless encoder instance

quoteAsCharArrayback to summary
public char[] quoteAsCharArray(CharSequence input)

Method that will escape text contents using JSON standard escaping, and return results as a character array.

Parameters
input:CharSequence

Value String to process

Returns:char[]

JSON-escaped String matching input

quoteAsStringback to summary
public void quoteAsString(CharSequence input, StringBuilder output)

Method that will quote text contents using JSON standard quoting, and append results to a supplied StringBuilder. Use this variant if you have e.g. a StringBuilder and want to avoid superfluous copying of it.

Parameters
input:CharSequence

Value CharSequence to process

output:StringBuilder

StringBuilder to append escaped contents to

quoteAsUTF8back to summary
public 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.

Parameters
text:CharSequence

Value String to process

Returns:byte[]

UTF-8 encoded bytes of JSON-escaped text

Annotations
@SuppressWarnings:resource