/** * Overridable factory method that actually instantiates desired * context object for async (non-blocking) parsing * * @since 2.9.7 */ protected IOContext _createNonBlockingContext(Object srcRef) { // [jackson-core#476]: disable buffer recycling for 2.9 to avoid concurrency issues; // easiest done by just constructing private "recycler": BufferRecycler recycler = new BufferRecycler(); return new IOContext(recycler, srcRef, false); }
/** * Overridable factory method that actually instantiates desired * context object. */ protected IOContext _createContext(Object srcRef, boolean resourceManaged) { return new IOContext(_getBufferRecycler(), srcRef, resourceManaged); }
/** * Overridable factory method that actually instantiates desired * context object. */ protected IOContext _createContext(Object srcRef, boolean resourceManaged, JsonEncoding enc) { return new IOContext(_getBufferRecycler(), srcRef, resourceManaged, enc); }
protected IOContext _createNonBlockingContext(Object srcRef) { // [jackson-core#476]: disable buffer recycling for 2.9 to avoid concurrency issues; // easiest done by just constructing private "recycler": BufferRecycler recycler = new BufferRecycler(); return new IOContext(recycler, srcRef, false); }
/** * Overridable factory method that actually instantiates desired * context object. */ protected IOContext _createContext(Object srcRef, boolean resourceManaged) { return new IOContext(_getBufferRecycler(), srcRef, resourceManaged, null); }
/** * 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)); }
/** * Creates a {@link SmileParser} from the inputstream with the supplied buf {@code inBuffer} to use. */ public static SmileParser newSmileParser(InputStream in, byte[] buf, int offset, int limit) throws IOException { return newSmileParser(in, buf, offset, limit, false, new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false)); }
/** * Creates a {@link SmileGenerator} for the outputstream with the supplied buf {@code outBuffer} to use. */ public static SmileGenerator newSmileGenerator(OutputStream out, byte[] buf) { return newSmileGenerator(out, buf, 0, false, new IOContext( DEFAULT_SMILE_FACTORY._getBufferRecycler(), out, false)); }
/** * Creates a {@link UTF8JsonGenerator} for the outputstream with the supplied buf {@code outBuffer} to use. */ public static UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf) { return newJsonGenerator(out, buf, 0, false, new IOContext( DEFAULT_JSON_FACTORY._getBufferRecycler(), out, false)); }
@Override public T decode(BsonReader reader, DecoderContext decoderContext) { final IOContext ioContext = new IOContext(new BufferRecycler(), null, false); final BsonParser parser = new BsonParser(ioContext, 0, (AbstractBsonReader) reader); try { return mapper.readValue(parser, getEncoderClass()); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Creates a json pipe from a byte array. */ public static Pipe newPipe(byte[] data, int offset, int length, 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); return newPipe(parser, numeric); }
/** * Creates a smile pipe from a byte array. */ public static Pipe newPipe(byte[] data, int offset, int length, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), data, false); final SmileParser parser = newSmileParser(null, data, offset, offset + length, false, context); return JsonIOUtil.newPipe(parser, numeric); // return JsonIOUtil.newPipe(DEFAULT_SMILE_FACTORY.createJsonParser(data, offset, length), numeric); }
/** * Creates a json pipe from an {@link InputStream}. */ public static Pipe newPipe(InputStream in, 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); return newPipe(parser, numeric); }
/** * Creates a smile pipe from an {@link InputStream}. */ public static Pipe newPipe(InputStream in, 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); return JsonIOUtil.newPipe(parser, numeric); // return JsonIOUtil.newPipe(DEFAULT_SMILE_FACTORY.createJsonParser(in), numeric); }
/** * 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_SMILE_FACTORY._getBufferRecycler(), data, false); final SmileParser parser = newSmileParser(null, data, offset, offset + length, false, context); // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(data, offset, length); try { JsonIOUtil.mergeFrom(parser, message, schema, numeric); } finally { parser.close(); } }
/** * 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(); } }
/** * 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_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.writeTo(generator, message, schema, numeric); } finally { generator.close(); } }
/** * 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(); } }
/** * 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(); } }
/** * Converts string to json */ private void compare(String string) throws IOException { JsonNode expected = mapper.readTree(string); // BSON likes encoding full document (not simple elements like BsonValue) if (!expected.isObject()) { ObjectNode temp = mapper.createObjectNode(); temp.set("ignore", expected); expected = temp; } BasicOutputBuffer buffer = new BasicOutputBuffer(); BsonWriter writer = new BsonBinaryWriter(buffer); BsonGenerator generator = new BsonGenerator(0, mapper, writer); // write 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 JsonNode actual = mapper.readValue(parser, JsonNode.class); check(actual).is(expected); }