/** * 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) { return new IOContext(_getBufferRecycler(), srcRef, resourceManaged); }
/** * 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) { return new IOContext(_getBufferRecycler(), srcRef, resourceManaged); }
/** * Method used by the factory to create parsing context for parser * instances. */ protected IOContext _createContext(Object srcRef, boolean resourceManaged) { return new IOContext(_getBufferRecycler(), srcRef, resourceManaged); }
/** * 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 Utf8Generator} for the outputstream with the supplied buf * {@code outBuffer} to use. */ public static Utf8Generator newJsonGenerator(OutputStream out, byte[] buf) { return newJsonGenerator(out, buf, 0, false, new IOContext( DEFAULT_JSON_FACTORY._getBufferRecycler(), out, 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 Utf8StreamParser} from the inputstream with the supplied * buf {@code inBuffer} to use. */ public static Utf8StreamParser 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 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} 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(); } }
public ByteBuffer toByteBuffer() throws IOException { BufferRecycler bufferRecycler = bufferThreadLocal.get(); ByteArrayBuilder bytes = new ByteArrayBuilder(bufferRecycler); IOContext ioContext = new IOContext(bufferRecycler, bytes, false); JsonGenerator gen = new Utf8Generator(ioContext, 0, null, bytes); gen.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES); gen.enable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS); gen.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII); writeJson(gen); gen.flush(); bytes.flush(); bytes.close(); return ByteBuffer.wrap(bytes.toByteArray()); }
/** * 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(); } }
/** * 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(); } }
/** * 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(); } }
/** * 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(); } }