public final char[] asQuotedChars() { char[] result = _quotedChars; if (result == null) { result = JsonStringEncoder.getInstance().quoteAsString(_value); _quotedChars = result; } return result; }
/** * Factory method for getting an instance; this is either recycled per-thread instance, * or a newly constructed one. */ public static JsonStringEncoder getInstance() { SoftReference<JsonStringEncoder> ref = _threadEncoder.get(); JsonStringEncoder enc = (ref == null) ? null : ref.get(); if (enc == null) { enc = new JsonStringEncoder(); _threadEncoder.set(new SoftReference<JsonStringEncoder>(enc)); } return enc; }
/** * Accessor for accessing value as is (without JSON quoting) * encoded using UTF-8 encoding. */ //@Override public final byte[] asQuotedUTF8() { byte[] result = _quotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().quoteAsUTF8(_value); _quotedUTF8Ref = result; } return result; }
/** * Accessor for accessing value that has been quoted using JSON * quoting rules, and encoded using UTF-8 encoding. */ //@Override public final byte[] asUnquotedUTF8() { byte[] result = _unquotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().encodeAsUTF8(_value); _unquotedUTF8Ref = result; } return result; }
private MessageFrame(SockJsMessage... messages) { this.messages = messages; data = ChannelBuffers.dynamicBuffer(); data.writeByte('a'); data.writeByte('['); for (int i = 0; i < messages.length; i++) { SockJsMessage message = messages[i]; data.writeByte('"'); char[] escaped = new JsonStringEncoder().quoteAsString(message.getMessage()); data.writeBytes(ChannelBuffers.copiedBuffer(escapeCharacters(escaped), CharsetUtil.UTF_8)); data.writeByte('"'); if (i < messages.length - 1) { data.writeByte(','); } } data.writeByte(']'); }
int escape = escCodes[ch]; outputPtr = _appendByteEscape(ch, escape, byteBuilder, outputPtr); outputBuffer = byteBuilder.getCurrentSegment(); continue main_loop; } else { // yes, surrogate pair if (ch > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(ch); _throwIllegalSurrogate(ch); ch = _convertSurrogate(ch, text.charAt(inputPtr++)); if (ch > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(ch);
} else { // yes, surrogate pair if (c > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(c); _throwIllegalSurrogate(c); c = _convertSurrogate(c, text.charAt(inputPtr++)); if (c > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(c);
/** * Accessor for accessing value that has been quoted using JSON * quoting rules, and encoded using UTF-8 encoding. */ //@Override public final byte[] asUnquotedUTF8() { byte[] result = _unquotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().encodeAsUTF8(_value); _unquotedUTF8Ref = result; } return result; }
int escape = escCodes[ch]; outputPtr = _appendByteEscape(ch, escape, byteBuilder, outputPtr); outputBuffer = byteBuilder.getCurrentSegment(); continue main_loop; } else { // yes, surrogate pair if (ch > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(ch); _throwIllegalSurrogate(ch); ch = _convertSurrogate(ch, text.charAt(inputPtr++)); if (ch > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(ch);
} else { // yes, surrogate pair if (c > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(c); _throwIllegalSurrogate(c); c = _convertSurrogate(c, text.charAt(inputPtr++)); if (c > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(c);
public static char[] jsonEncoding(String rawString) { return JsonStringEncoder.getInstance().quoteAsString(rawString); } }
/** * Accessor for accessing value as is (without JSON quoting) * encoded using UTF-8 encoding. */ //@Override public final byte[] asQuotedUTF8() { byte[] result = _quotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().quoteAsUTF8(_value); _quotedUTF8Ref = result; } return result; }
/** * Accessor for accessing value that has been quoted using JSON * quoting rules, and encoded using UTF-8 encoding. */ public final byte[] asUnquotedUTF8() { byte[] result = _unquotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().encodeAsUTF8(_value); _unquotedUTF8Ref = result; } return result; }
int escape = escCodes[ch]; outputPtr = _appendByteEscape(ch, escape, byteBuilder, outputPtr); outputBuffer = byteBuilder.getCurrentSegment(); continue main_loop; } else { // yes, surrogate pair if (ch > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(ch); _throwIllegalSurrogate(ch); ch = _convertSurrogate(ch, text.charAt(inputPtr++)); if (ch > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(ch);
} else { // yes, surrogate pair if (c > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(c); _throwIllegalSurrogate(c); c = _convertSurrogate(c, text.charAt(inputPtr++)); if (c > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(c);
/** * Factory method for getting an instance; this is either recycled per-thread instance, * or a newly constructed one. */ public static JsonStringEncoder getInstance() { SoftReference<JsonStringEncoder> ref = _threadEncoder.get(); JsonStringEncoder enc = (ref == null) ? null : ref.get(); if (enc == null) { enc = new JsonStringEncoder(); _threadEncoder.set(new SoftReference<JsonStringEncoder>(enc)); } return enc; }
private static JsonNode toJsonNode(Object o) { try { String s; if (o instanceof ByteBuffer) { // special case since GenericData.toString() is incorrect for bytes // note that this does not handle the case of a default value with nested bytes ByteBuffer bytes = ((ByteBuffer) o); bytes.mark(); byte[] data = new byte[bytes.remaining()]; bytes.get(data); bytes.reset(); // put the buffer back the way we got it s = new String(data, "ISO-8859-1"); char[] quoted = JsonStringEncoder.getInstance().quoteAsString(s); s = "\"" + new String(quoted) + "\""; } else if (o instanceof byte[]) { s = new String((byte[]) o, "ISO-8859-1"); char[] quoted = JsonStringEncoder.getInstance().quoteAsString(s); s = '\"' + new String(quoted) + '\"'; } else { s = GenericData.get().toString(o); } return new ObjectMapper().readTree(s); } catch (IOException e) { throw new SchemaBuilderException(e); } } }
/** * Accessor for accessing value as is (without JSON quoting) * encoded using UTF-8 encoding. */ public final byte[] asQuotedUTF8() { byte[] result = _quotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().quoteAsUTF8(_value); _quotedUTF8Ref = result; } return result; }
/** * Accessor for accessing value that has been quoted using JSON * quoting rules, and encoded using UTF-8 encoding. */ @Override public final byte[] asUnquotedUTF8() { byte[] result = _unquotedUTF8Ref; if (result == null) { result = JsonStringEncoder.getInstance().encodeAsUTF8(_value); _unquotedUTF8Ref = result; } return result; }
int escape = escCodes[ch]; outputPtr = _appendByteEscape(ch, escape, byteBuilder, outputPtr); outputBuffer = byteBuilder.getCurrentSegment(); continue main_loop; } else { // yes, surrogate pair if (ch > SURR1_LAST) { // must be from first range _throwIllegalSurrogate(ch); _throwIllegalSurrogate(ch); ch = _convertSurrogate(ch, text.charAt(inputPtr++)); if (ch > 0x10FFFF) { // illegal, as per RFC 4627 _throwIllegalSurrogate(ch);