Java 类com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper 实例源码

项目:athena    文件:JsonRpcReaderUtil.java   
/**
 * Check whether the encoding is valid.
 * @param in input of bytes
 * @throws IOException this is an IO exception
 * @throws UnsupportedException this is an unsupported exception
 */
private static void checkEncoding(ByteBuf in) throws IOException {
    int inputStart = 0;
    int inputLength = 4;
    fliterCharaters(in);
    byte[] buff = new byte[4];
    in.getBytes(in.readerIndex(), buff);
    ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(),
                                                                                       null,
                                                                                       false),
                                                                         buff, inputStart,
                                                                         inputLength);
    JsonEncoding jsonEncoding = strapper.detectEncoding();
    if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
        throw new UnsupportedException("Only UTF-8 encoding is supported.");
    }
}
项目:onos    文件:JsonRpcReaderUtil.java   
/**
 * Check whether the encoding is valid.
 * @param in input of bytes
 * @throws IOException this is an IO exception
 * @throws UnsupportedException this is an unsupported exception
 */
private static void checkEncoding(ByteBuf in) throws IOException {
    int inputStart = 0;
    int inputLength = 4;
    fliterCharaters(in);
    byte[] buff = new byte[4];
    in.getBytes(in.readerIndex(), buff);
    ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(),
                                                                                       null,
                                                                                       false),
                                                                         buff, inputStart,
                                                                         inputLength);
    JsonEncoding jsonEncoding = strapper.detectEncoding();
    if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
        throw new UnsupportedException("Only UTF-8 encoding is supported.");
    }
}
项目:QuizUpWinner    文件:JsonFactory.java   
protected JsonParser _createParser(InputStream paramInputStream, IOContext paramIOContext)
{
  return new ByteSourceJsonBootstrapper(paramIOContext, paramInputStream).constructParser(this._parserFeatures, this._objectCodec, this._rootByteSymbols, this._rootCharSymbols, isEnabled(Feature.CANONICALIZE_FIELD_NAMES), isEnabled(Feature.INTERN_FIELD_NAMES));
}
项目:QuizUpWinner    文件:JsonFactory.java   
protected JsonParser _createParser(byte[] paramArrayOfByte, int paramInt1, int paramInt2, IOContext paramIOContext)
{
  return new ByteSourceJsonBootstrapper(paramIOContext, paramArrayOfByte, paramInt1, paramInt2).constructParser(this._parserFeatures, this._objectCodec, this._rootByteSymbols, this._rootCharSymbols, isEnabled(Feature.CANONICALIZE_FIELD_NAMES), isEnabled(Feature.INTERN_FIELD_NAMES));
}
项目:QuizUpWinner    文件:JsonFactory.java   
public MatchStrength hasJSONFormat(InputAccessor paramInputAccessor)
{
  return ByteSourceJsonBootstrapper.hasJSONFormat(paramInputAccessor);
}
项目:ovsdb    文件:JsonRpcDecoder.java   
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {

    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 = jacksonJsonFactory.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();
    }
}