/** * 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)); }
/** * Serializes the {@code message} into an {@link OutputStream} * using the given {@code schema}. * * 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(); } }
/** * Serializes the {@code messages} into the stream using the given schema. * * 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_JSON_FACTORY._getBufferRecycler(), out, false); final JsonGenerator generator = newJsonGenerator(out, buffer.buffer, 0, false, context); try { 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(); } }
/** * 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(); } }