类com.fasterxml.jackson.core.io.IOContext源码实例Demo

下面列出了怎么用com.fasterxml.jackson.core.io.IOContext的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: protostuff   文件: JsonIOUtil.java
/**
 * Parses the {@code messages} from the stream using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used when reading the message.
 */
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema,
        boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            in, false);
    final JsonParser parser = newJsonParser(in, buffer.buffer, 0, 0, false, context);
    try
    {
        return parseListFrom(parser, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码2 项目: lams   文件: UTF8StreamJsonParser.java
public UTF8StreamJsonParser(IOContext ctxt, int features, InputStream in,
        ObjectCodec codec, ByteQuadsCanonicalizer sym,
        byte[] inputBuffer, int start, int end,
        boolean bufferRecyclable)
{
    super(ctxt, features);
    _inputStream = in;
    _objectCodec = codec;
    _symbols = sym;
    _inputBuffer = inputBuffer;
    _inputPtr = start;
    _inputEnd = end;
    _currInputRowStart = start;
    // If we have offset, need to omit that from byte offset, so:
    _currInputProcessed = -start;
    _bufferRecyclable = bufferRecyclable;
}
 
源代码3 项目: protostuff   文件: JsonIOUtil.java
/**
 * Serializes the {@code messages} into the stream using the given schema.
 */
public static <T> void writeListTo(OutputStream out, List<T> messages,
        Schema<T> schema, boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            out, false);

    final JsonGenerator generator = newJsonGenerator(out,
            context.allocWriteEncodingBuffer(), 0, true, context);
    /*
     * final JsonGenerator generator = DEFAULT_JSON_FACTORY.createJsonGenerator(out, JsonEncoding.UTF8);
     */
    try
    {
        writeListTo(generator, messages, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
源代码4 项目: lams   文件: UTF8JsonGenerator.java
public UTF8JsonGenerator(IOContext ctxt, int features, ObjectCodec codec,
        OutputStream out,
        byte[] outputBuffer, int outputOffset, boolean bufferRecyclable)
{
    
    super(ctxt, features, codec);
    _outputStream = out;
    _bufferRecyclable = bufferRecyclable;
    _outputTail = outputOffset;
    _outputBuffer = outputBuffer;
    _outputEnd = _outputBuffer.length;
    // up to 6 bytes per char (see above), rounded up to 1/8
    _outputMaxContiguous = (_outputEnd >> 3);
    _charBuffer = ctxt.allocConcatBuffer();
    _charBufferLength = _charBuffer.length;
}
 
源代码5 项目: protostuff   文件: JsonIOUtil.java
/**
 * Merges the {@code message} with the byte array using the given {@code schema}.
 */
public static <T> void mergeFrom(byte[] data, int offset, int length, T message,
        Schema<T> schema, boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            data, false);
    final JsonParser parser = newJsonParser(null, data, offset, offset + length, false,
            context);
    /*
     * final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(data, offset, length);
     */
    try
    {
        mergeFrom(parser, message, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码6 项目: protostuff   文件: JsonIOUtil.java
/**
 * Parses the {@code messages} from the stream using the given {@code schema}.
 */
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema,
        boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            in, false);
    final JsonParser parser = newJsonParser(in, context.allocReadIOBuffer(), 0, 0,
            true, context);
    // final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(in);
    try
    {
        return parseListFrom(parser, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码7 项目: dremio-oss   文件: JsonIOUtils.java
/**
 * Merges the {@code message} with the byte array using the given {@code schema}.
 */
public static <T> void mergeFrom(byte[] data, int offset, int length, T message,
                                 Schema<T> schema, boolean numeric) throws IOException {
  final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
    data, false);
  final JsonParser parser = newJsonParser(null, data, offset, offset + length, false,
    context);
  /*
   * final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(data, offset, length);
   */
  try {
    mergeFrom(parser, message, schema, numeric);
  } finally {
    parser.close();
  }
}
 
源代码8 项目: openbd-core   文件: UTF8StreamJsonParser.java
public UTF8StreamJsonParser(IOContext ctxt, int features, InputStream in,
        ObjectCodec codec, ByteQuadsCanonicalizer sym,
        byte[] inputBuffer, int start, int end,
        boolean bufferRecyclable)
{
    super(ctxt, features);
    _inputStream = in;
    _objectCodec = codec;
    _symbols = sym;
    _inputBuffer = inputBuffer;
    _inputPtr = start;
    _inputEnd = end;
    _currInputRowStart = start;
    // If we have offset, need to omit that from byte offset, so:
    _currInputProcessed = -start;
    _bufferRecyclable = bufferRecyclable;
}
 
源代码9 项目: openbd-core   文件: ReaderBasedJsonParser.java
/**
 * Method called when caller wants to provide input buffer directly,
 * and it may or may not be recyclable use standard recycle context.
 * 
 * @since 2.4
 */
public ReaderBasedJsonParser(IOContext ctxt, int features, Reader r,
        ObjectCodec codec, CharsToNameCanonicalizer st,
        char[] inputBuffer, int start, int end,
        boolean bufferRecyclable)
{
    super(ctxt, features);
    _reader = r;
    _inputBuffer = inputBuffer;
    _inputPtr = start;
    _inputEnd = end;
    _objectCodec = codec;
    _symbols = st;
    _hashSeed = st.hashSeed();
    _bufferRecyclable = bufferRecyclable;
}
 
源代码10 项目: immutables   文件: BsonParserTest.java
/**
 * Read and Write in Jackson API but using BSON reader/writer adapters
 */
private void jacksonThenJackson(String json) throws IOException {
  ObjectNode expected = maybeWrap(mapper.readTree(json));

  BasicOutputBuffer buffer = new BasicOutputBuffer();
  BsonWriter writer = new BsonBinaryWriter(buffer);

  BsonGenerator generator = new BsonGenerator(0, writer);
  // write with Jackson
  mapper.writeValue(generator, expected);

  BsonBinaryReader reader = new BsonBinaryReader(ByteBuffer.wrap(buffer.toByteArray()));
  IOContext ioContext = new IOContext(new BufferRecycler(), null, false);
  BsonParser parser = new BsonParser(ioContext, 0, reader);

  // read with Jackson
  JsonNode actual = mapper.readValue(parser, JsonNode.class);
  check(actual).is(expected);
}
 
源代码11 项目: protostuff   文件: JsonIOUtil.java
/**
 * Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used as the primary buffer when writing the message.
 */
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema,
        boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            out, false);

    final JsonGenerator generator = newJsonGenerator(out, buffer.buffer, 0, false,
            context);
    try
    {
        writeTo(generator, message, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
源代码12 项目: protostuff   文件: JsonIOUtil.java
/**
 * Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}.
 */
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema,
        boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            out, false);

    final JsonGenerator generator = newJsonGenerator(out,
            context.allocWriteEncodingBuffer(), 0, true, context);

    /*
     * final JsonGenerator generator = DEFAULT_JSON_FACTORY.createJsonGenerator(out, JsonEncoding.UTF8);
     */
    try
    {
        writeTo(generator, message, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
源代码13 项目: divolte-collector   文件: MincodeFactoryTest.java
@Override
public Reader decorate(final IOContext ctxt, final Reader r) throws IOException {
    return new Reader() {
        @Override
        public int read(final char[] cbuf,
                        final int off,
                        final int len) throws IOException {
            final int count = r.read(cbuf, off, len);
            invert(cbuf, off, len);
            return count;
        }

        @Override
        public void close() throws IOException {
            r.close();
        }
    };
}
 
源代码14 项目: 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.");
    }
}
 
源代码15 项目: protostuff   文件: SmileIOUtil.java
/**
 * Merges the {@code message} from the {@link InputStream} using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used when reading the message.
 */
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema,
        boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            in, false);
    final SmileParser parser = newSmileParser(in, buffer.buffer, 0, 0, false, context);

    // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in);

    try
    {
        JsonIOUtil.mergeFrom(parser, message, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码16 项目: protostuff   文件: JsonIOUtil.java
/**
 * Merges the {@code message} from the {@link InputStream} using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used when reading the message.
 */
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema,
        boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
            in, false);
    final JsonParser parser = newJsonParser(in, buffer.buffer, 0, 0, false, context);
    try
    {
        mergeFrom(parser, message, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码17 项目: protostuff   文件: SmileIOUtil.java
/**
 * Serializes the {@code messages} into the stream using the given schema.
 */
public static <T> void writeListTo(OutputStream out, List<T> messages,
        Schema<T> schema, boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            out, false);

    final SmileGenerator generator = newSmileGenerator(out,
            context.allocWriteEncodingBuffer(), 0, true, context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
    try
    {
        JsonIOUtil.writeListTo(generator, messages, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
源代码18 项目: protostuff   文件: SmileIOUtil.java
/**
 * Serializes the {@code messages} into the stream using the given schema.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used as the primary buffer when writing the message.
 */
public static <T> void writeListTo(OutputStream out, List<T> messages,
        Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            out, false);

    final SmileGenerator generator = newSmileGenerator(out, buffer.buffer, 0, false,
            context);

    // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
    try
    {
        JsonIOUtil.writeListTo(generator, messages, schema, numeric);
    }
    finally
    {
        generator.close();
    }
}
 
源代码19 项目: protostuff   文件: SmileIOUtil.java
/**
 * Parses the {@code messages} from the stream using the given {@code schema}.
 */
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema,
        boolean numeric) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            in, false);
    final SmileParser parser = newSmileParser(in, context.allocReadIOBuffer(), 0, 0,
            true, context);

    // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in);
    try
    {
        return JsonIOUtil.parseListFrom(parser, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码20 项目: protostuff   文件: SmileIOUtil.java
/**
 * Parses the {@code messages} from the stream using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used when reading the message.
 */
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema,
        boolean numeric, LinkedBuffer buffer) throws IOException
{
    final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(),
            in, false);
    final SmileParser parser = newSmileParser(in, buffer.buffer, 0, 0, false, context);

    // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in);
    try
    {
        return JsonIOUtil.parseListFrom(parser, schema, numeric);
    }
    finally
    {
        parser.close();
    }
}
 
源代码21 项目: datawave   文件: ProtostuffMessageBodyWriter.java
@SuppressWarnings("unchecked")
@Override
public void writeTo(Object message, Class<?> clazz, Type type, Annotation[] annotations, MediaType media, MultivaluedMap<String,Object> httpHeaders,
                OutputStream out) throws IOException, WebApplicationException {
    
    // TODO: Figure out a method to add the proto file location in the response headers.
    // This map must be mofified before any data is written to out,
    // since at that time the response headers will be flushed.
    
    Schema<Object> schema = null;
    if (message instanceof Message) {
        Message<Object> msg = (Message<Object>) message;
        schema = msg.cachedSchema();
    } else {
        schema = (Schema<Object>) RuntimeSchema.getSchema(clazz);
    }
    
    try {
        if (MediaType.APPLICATION_XML_TYPE.equals(media) || MediaType.TEXT_XML_TYPE.equals(media)) {
            XmlIOUtil.writeTo(out, message, schema);
        } else if ("text/yaml".equals(media.toString()) || "text/x-yaml".equals(media.toString()) || "application/x-yaml".equals(media.toString())) {
            YamlIOUtil.writeTo(out, message, schema, buffer);
        } else if ("application/x-protobuf".equals(media.toString())) {
            ProtobufIOUtil.writeTo(out, message, schema, buffer);
        } else if ("application/x-protostuff".equals(media.toString())) {
            ProtostuffIOUtil.writeTo(out, message, schema, buffer);
        } else if (MediaType.APPLICATION_JSON_TYPE.equals(media)) {
            IOContext ctx = new IOContext(JsonIOUtil.DEFAULT_JSON_FACTORY._getBufferRecycler(), out, false);
            UTF8JsonGenerator generator = new UTF8JsonGenerator(ctx, JsonIOUtil.DEFAULT_JSON_FACTORY.getGeneratorFeatures(),
                            JsonIOUtil.DEFAULT_JSON_FACTORY.getCodec(), out);
            try {
                JsonIOUtil.writeTo(generator, message, schema, false);
            } finally {
                generator.close();
            }
        }
    } finally {
        buffer.clear();
    }
}
 
源代码22 项目: jackson-dataformat-hocon   文件: HoconFactory.java
@SuppressWarnings("resource")
@Override
public HoconTreeTraversingParser createParser(byte[] data)
    throws IOException, JsonParseException
{
    IOContext ctxt = _createContext(data, true);
    // [JACKSON-512]: allow wrapping with InputDecorator
    if (_inputDecorator != null) {
        InputStream in = _inputDecorator.decorate(ctxt, data, 0, data.length);
        if (in != null) {
            return _createParser(in, ctxt);
        }
    }
    return _createParser(data, 0, data.length, ctxt);
}
 
源代码23 项目: lams   文件: JsonGeneratorImpl.java
public JsonGeneratorImpl(IOContext ctxt, int features, ObjectCodec codec)
{
    super(features, codec);
    _ioContext = ctxt;
    if (Feature.ESCAPE_NON_ASCII.enabledIn(features)) {
        // inlined `setHighestNonEscapedChar()`
        _maximumNonEscapedChar = 127;
    }
    _cfgUnqNames = !Feature.QUOTE_FIELD_NAMES.enabledIn(features);
}
 
源代码24 项目: lams   文件: ReaderBasedJsonParser.java
/**
 * Method called when input comes as a {@link java.io.Reader}, and buffer allocation
 * can be done using default mechanism.
 */
public ReaderBasedJsonParser(IOContext ctxt, int features, Reader r,
    ObjectCodec codec, CharsToNameCanonicalizer st)
{
    super(ctxt, features);
    _reader = r;
    _inputBuffer = ctxt.allocTokenBuffer();
    _inputPtr = 0;
    _inputEnd = 0;
    _objectCodec = codec;
    _symbols = st;
    _hashSeed = st.hashSeed();
    _bufferRecyclable = true;
}
 
源代码25 项目: lams   文件: NonBlockingJsonParserBase.java
public NonBlockingJsonParserBase(IOContext ctxt, int parserFeatures,
        ByteQuadsCanonicalizer sym)
{
    super(ctxt, parserFeatures);
    _symbols = sym;
    _currToken = null;
    _majorState = MAJOR_INITIAL;
    _majorStateAfterValue = MAJOR_ROOT;
}
 
源代码26 项目: dremio-oss   文件: JsonIOUtils.java
/**
 * Creates a {@link UTF8StreamJsonParser} from the inputstream with the supplied buf {@code inBuffer} to use.
 */
public static UTF8StreamJsonParser newJsonParser(InputStream in, byte[] buf,
                                                 int offset, int limit) throws IOException {
  return newJsonParser(in, buf, offset, limit, false,
    new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), in,
      false));
}
 
源代码27 项目: dremio-oss   文件: JsonIOUtils.java
/**
 * Creates a {@link UTF8StreamJsonParser} from the inputstream with the supplied buf {@code inBuffer} to use.
 */
static UTF8StreamJsonParser newJsonParser(InputStream in, byte[] buf,
                                          int offset, int limit, boolean bufferRecyclable, IOContext context)
  throws IOException {
  return new UTF8StreamJsonParser(context,
    DEFAULT_JSON_FACTORY.getParserFeatures(), in,
    DEFAULT_JSON_FACTORY.getCodec(),
    DEFAULT_JSON_FACTORY.getRootByteSymbols().makeChild(1),
    buf, offset, limit, bufferRecyclable);
}
 
源代码28 项目: dremio-oss   文件: JsonIOUtils.java
/**
 * Creates a {@link UTF8JsonGenerator} for the outputstream with the supplied buf {@code outBuffer} to use.
 */
static UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf, int offset,
                                          boolean bufferRecyclable, IOContext context) {
  context.setEncoding(JsonEncoding.UTF8);

  return new UTF8JsonGenerator(context,
    DEFAULT_JSON_FACTORY.getGeneratorFeatures(),
    DEFAULT_JSON_FACTORY.getCodec(),
    out,
    buf,
    offset,
    bufferRecyclable);
}
 
源代码29 项目: dremio-oss   文件: JsonIOUtils.java
/**
 * Merges the {@code message} from the {@link InputStream} using the given {@code schema}.
 */
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema,
                                 boolean numeric) throws IOException {
  final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
    in, false);
  // final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(in);
  try (JsonParser parser = newJsonParser(in, context.allocReadIOBuffer(), 0, 0,
    true, context)) {
    mergeFrom(parser, message, schema, numeric);
  }
}
 
源代码30 项目: dremio-oss   文件: JsonIOUtils.java
/**
 * Merges the {@code message} from the {@link InputStream} using the given {@code schema}.
 * <p>
 * The {@link LinkedBuffer}'s internal byte array will be used when reading the message.
 */
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema,
                                 boolean numeric, LinkedBuffer buffer) throws IOException {
  final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(),
    in, false);
  try (JsonParser parser = newJsonParser(in, buffer.buffer, 0, 0, false, context)) {
    mergeFrom(parser, message, schema, numeric);
  }
}
 
 同包方法