Java Code Examples for com.fasterxml.jackson.core.JsonEncoding#getJavaName()
The following examples show how to use
com.fasterxml.jackson.core.JsonEncoding#getJavaName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KriptonXmlContext.java From kripton with Apache License 2.0 | 5 votes |
public XmlWrapperSerializer createSerializer(OutputStream out, JsonEncoding encoding) { try { return new XmlWrapperSerializer(new XMLSerializer(new OutputStreamWriter(out, encoding.getJavaName()))); } catch (Exception e) { e.printStackTrace(); throw new KriptonRuntimeException(e); } }
Example 2
Source File: HoconFactory.java From jackson-dataformat-hocon with Apache License 2.0 | 5 votes |
protected Reader _createReader(InputStream in, JsonEncoding enc, IOContext ctxt) throws IOException { if (enc == null) { enc = JsonEncoding.UTF8; } // default to UTF-8 if encoding missing if (enc == JsonEncoding.UTF8) { boolean autoClose = ctxt.isResourceManaged() || isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE); return new UTF8Reader(in, autoClose); } return new InputStreamReader(in, enc.getJavaName()); }
Example 3
Source File: HoconFactory.java From jackson-dataformat-hocon with Apache License 2.0 | 5 votes |
protected Reader _createReader(byte[] data, int offset, int len, JsonEncoding enc, IOContext ctxt) throws IOException { if (enc == null) { enc = JsonEncoding.UTF8; } // default to UTF-8 if encoding missing if (enc == null || enc == JsonEncoding.UTF8) { return new UTF8Reader(data, offset, len, true); } ByteArrayInputStream in = new ByteArrayInputStream(data, offset, len); return new InputStreamReader(in, enc.getJavaName()); }
Example 4
Source File: JsonRpcDecoder.java From ovsdb with Eclipse Public License 1.0 | 4 votes |
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf buf, final List<Object> out) throws IOException { LOG.trace("readable bytes {}, records read {}, incomplete record bytes {}", buf.readableBytes(), recordsRead, lastRecordBytes); if (lastRecordBytes == 0) { if (buf.readableBytes() < 4) { return; //wait for more data } skipSpaces(buf); byte[] buff = new byte[4]; buf.getBytes(buf.readerIndex(), buff); ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(jacksonIOContext, buff, 0, 4); JsonEncoding jsonEncoding = strapper.detectEncoding(); if (!JsonEncoding.UTF8.equals(jsonEncoding)) { throw new InvalidEncodingException(jsonEncoding.getJavaName(), "currently only UTF-8 is supported"); } } int index = lastRecordBytes + buf.readerIndex(); for (; index < buf.writerIndex(); index++) { switch (buf.getByte(index)) { case '{': if (!inS) { leftCurlies++; } break; case '}': if (!inS) { rightCurlies++; } break; case '"': if (buf.getByte(index - 1) != '\\') { inS = !inS; } break; default: break; } if (leftCurlies != 0 && leftCurlies == rightCurlies && !inS) { ByteBuf slice = buf.readSlice(1 + index - buf.readerIndex()); JsonParser jp = JSON_FACTORY.createParser((InputStream) new ByteBufInputStream(slice)); JsonNode root = jp.readValueAsTree(); out.add(root); leftCurlies = 0; rightCurlies = 0; lastRecordBytes = 0; recordsRead++; break; } /* * Changing this limit to being a warning, we do not wish to "break" in scale environment * and currently this limits the ovs of having only around 50 ports defined... * I do acknowledge the fast that this might be risky in case of huge amount of strings * in which the controller can crash with an OOM, however seems that we need a really huge * ovs to reach that limit. */ //We do not want to issue a log message on every extent of the buffer //hence logging only once if (index - buf.readerIndex() >= maxFrameLength && !maxFrameLimitWasReached) { maxFrameLimitWasReached = true; LOG.warn("***** OVSDB Frame limit of {} bytes has been reached! *****", this.maxFrameLength); } } // end of stream, save the incomplete record index to avoid reexamining the whole on next run if (index >= buf.writerIndex()) { lastRecordBytes = buf.readableBytes(); } }