public final class JsonStringEncoder
extends java.lang.Object
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.
NOTE: starting with 2.9.3, access to most functionality should go through
BufferRecyclers
and NOT directly through this class.
Modifier and Type | Field and Description |
---|---|
protected ByteArrayBuilder |
_bytes
Lazily-constructed builder used for UTF-8 encoding of text values
(quoted and unquoted)
|
protected char[] |
_qbuf
Temporary buffer used for composing quote/escape sequences
|
protected TextBuffer |
_text
Lazily constructed text buffer used to produce JSON encoded Strings
as characters (without UTF-8 encoding)
|
private static byte[] |
HB |
private static char[] |
HC |
private static int |
SURR1_FIRST |
private static int |
SURR1_LAST |
private static int |
SURR2_FIRST |
private static int |
SURR2_LAST |
Constructor and Description |
---|
JsonStringEncoder() |
Modifier and Type | Method 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) |
byte[] |
encodeAsUTF8(java.lang.String text)
Will encode given String as UTF-8 (without any quoting), return
resulting byte array.
|
static JsonStringEncoder |
getInstance()
Deprecated.
Since 2.9.2 use
BufferRecyclers.getJsonStringEncoder() instead |
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 supplied
StringBuilder . |
char[] |
quoteAsString(java.lang.String input)
Method that will quote text contents using JSON standard quoting,
and return results as a character array
|
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.
|
private static final char[] HC
private static final byte[] HB
private static final int SURR1_FIRST
private static final int SURR1_LAST
private static final int SURR2_FIRST
private static final int SURR2_LAST
protected TextBuffer _text
protected ByteArrayBuilder _bytes
protected final char[] _qbuf
@Deprecated public static JsonStringEncoder getInstance()
BufferRecyclers.getJsonStringEncoder()
insteadpublic char[] quoteAsString(java.lang.String input)
public void quoteAsString(java.lang.CharSequence input, java.lang.StringBuilder output)
StringBuilder
.
Use this variant if you have e.g. a StringBuilder
and want to avoid superfluous copying of it.public byte[] quoteAsUTF8(java.lang.String text)
public byte[] encodeAsUTF8(java.lang.String text)
private int _appendNumeric(int value, char[] qbuf)
private int _appendNamed(int esc, char[] qbuf)
private int _appendByte(int ch, int esc, ByteArrayBuilder bb, int ptr)
private static int _convert(int p1, int p2)
private static void _illegal(int c)