Refine search
@Override @SuppressWarnings("deprecation") protected char[] applyJsonQuoting(String content) { return JsonStringEncoder.getInstance().quoteAsString(content); }
public static String quoteStringLiteralForJson(String string) { return '"' + new String(JsonStringEncoder.getInstance().quoteAsUTF8(string)) + '"'; }
public static String quoteString( String s ) { JsonStringEncoder encoder = new JsonStringEncoder(); return new String( encoder.quoteAsUTF8( s ) ); }
/** * 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; }
/** * @since 2.9.4 */ public static void quoteAsJsonText(CharSequence input, StringBuilder output) { getJsonStringEncoder().quoteAsString(input, output); }
final int[] escCodes = CharTypes.get7BitOutputEscapes(); int escape = escCodes[ch]; outputPtr = _appendByte(ch, escape, bb, outputPtr); outputBuffer = bb.getCurrentSegment(); continue main; } else { // yes, surrogate pair if (ch > SURR1_LAST) { // must be from first range _illegal(ch); _illegal(ch); ch = _convert(ch, text.charAt(inputPtr++)); if (ch > 0x10FFFF) { // illegal, as per RFC 4627 _illegal(ch);
private static ByteBuf generateContent(final List<String> messages) { final JsonStringEncoder jsonEndocder = new JsonStringEncoder(); final ByteBuf content = Unpooled.buffer(); content.writeByte('a').writeByte('['); final int size = messages.size(); for (int i = 0; i < size; i++) { content.writeByte('"'); final String element = messages.get(i); if (element == null) { messages.subList(i, size).clear(); break; } final String escaped = escapeCharacters(jsonEndocder.quoteAsString(element)); final ByteBuf escapedBuf = Unpooled.copiedBuffer(escaped, CharsetUtil.UTF_8); content.writeBytes(escapedBuf).writeByte('"'); escapedBuf.release(); if (i < size - 1) { content.writeByte(','); } } return content.writeByte(']'); }
public static JsonStringEncoder getJsonStringEncoder() { SoftReference<JsonStringEncoder> ref = _encoderRef.get(); JsonStringEncoder enc = (ref == null) ? null : ref.get(); if (enc == null) { enc = new JsonStringEncoder(); _encoderRef.set(new SoftReference<JsonStringEncoder>(enc)); } return enc; }
/** * @since 2.9.4 */ public static byte[] quoteAsJsonUTF8(String rawText) { return getJsonStringEncoder().quoteAsUTF8(rawText); } }
/** * Helper method for encoding given String as UTF-8 encoded * * @since 2.9.4 */ public static byte[] encodeAsUTF8(String text) { return getJsonStringEncoder().encodeAsUTF8(text); }
/** * 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; }
/** * @since 2.9.4 */ public static char[] quoteAsJsonText(String rawText) { return getJsonStringEncoder().quoteAsString(rawText); }
final int[] escCodes = CharTypes.get7BitOutputEscapes(); int escape = escCodes[ch]; outputPtr = _appendByte(ch, escape, bb, outputPtr); outputBuffer = bb.getCurrentSegment(); continue main; } else { // yes, surrogate pair if (ch > SURR1_LAST) { // must be from first range _illegal(ch); _illegal(ch); ch = _convert(ch, text.charAt(inputPtr++)); if (ch > 0x10FFFF) { // illegal, as per RFC 4627 _illegal(ch);
private static ByteBuf generateContent(final List<String> messages) { final JsonStringEncoder jsonEndocder = new JsonStringEncoder(); final ByteBuf content = Unpooled.buffer(); content.writeByte('a').writeByte('['); final int size = messages.size(); for (int i = 0; i < size; i++) { content.writeByte('"'); final String element = messages.get(i); if (element == null) { messages.subList(i, size).clear(); break; } final String escaped = escapeCharacters(jsonEndocder.quoteAsString(element)); final ByteBuf escapedBuf = Unpooled.copiedBuffer(escaped, CharsetUtil.UTF_8); content.writeBytes(escapedBuf).writeByte('"'); escapedBuf.release(); if (i < size - 1) { content.writeByte(','); } } return content.writeByte(']'); }
public static JsonStringEncoder getJsonStringEncoder() { SoftReference<JsonStringEncoder> ref = _encoderRef.get(); JsonStringEncoder enc = (ref == null) ? null : ref.get(); if (enc == null) { enc = new JsonStringEncoder(); _encoderRef.set(new SoftReference<JsonStringEncoder>(enc)); } return enc; }
/** * @since 2.9.4 */ public static byte[] quoteAsJsonUTF8(String rawText) { return getJsonStringEncoder().quoteAsUTF8(rawText); } }
/** * Helper method for encoding given String as UTF-8 encoded * * @since 2.9.4 */ public static byte[] encodeAsUTF8(String text) { return getJsonStringEncoder().encodeAsUTF8(text); }
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. */ @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; }