Top Description Fields Constructors Methods
com.fasterxml.jackson.core.io

public final Class JsonStringEncoder

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.Arrays, com.fasterxml.jackson.core.util.ByteArrayBuilder, .TextBuffer

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

Modifier and TypeField and Description
private static final byte[]
private static final char[]
private static final JsonStringEncoder
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv 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)

pack-priv static int
_initialByteBufSize(int strLen)

pack-priv static int
_initialCharBufSize(int strLen)

private char[]
public byte[]

Returns:

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

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

public byte[]

Returns:

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

Overloaded variant of encodeAsUTF8(String).

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
quoteAsString
(String
Value String to process
input
)

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

public char[]

Returns:

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

Overloaded variant of quoteAsString(String).

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
(String
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
pack-priv static final int MAX_BYTE_BUFFER_SIZE
MAX_CHAR_BUFFER_SIZEback to summary
pack-priv static final int MAX_CHAR_BUFFER_SIZE
MIN_BYTE_BUFFER_SIZEback to summary
pack-priv static final int MIN_BYTE_BUFFER_SIZE
MIN_CHAR_BUFFER_SIZEback to summary
pack-priv 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
pack-priv static int _initialByteBufSize(int strLen)
_initialCharBufSizeback to summary
pack-priv static int _initialCharBufSize(int strLen)
_qbufback to summary
private char[] _qbuf()
encodeAsUTF8back to summary
public byte[] encodeAsUTF8(String text)

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

Parameters
text:String

Value String to process

Returns:byte[]

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

Annotations
@SuppressWarnings:resource
encodeAsUTF8back to summary
public byte[] encodeAsUTF8(CharSequence text)

Overloaded variant of encodeAsUTF8(String).

Parameters
text:CharSequence

Value CharSequence to process

Returns:byte[]

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

Annotations
@SuppressWarnings:resource
Since
2.11
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

quoteAsStringback to summary
public char[] quoteAsString(String input)

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

Parameters
input:String

Value String to process

Returns:char[]

JSON-escaped String matching input

quoteAsStringback to summary
public char[] quoteAsString(CharSequence input)

Overloaded variant of quoteAsString(String).

Parameters
input:CharSequence

Value CharSequence to process

Returns:char[]

JSON-escaped String matching input

Since
2.10
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

Since
2.8
quoteAsUTF8back to summary
public byte[] quoteAsUTF8(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:String

Value String to process

Returns:byte[]

UTF-8 encoded bytes of JSON-escaped text

Annotations
@SuppressWarnings:resource