/** * Merges the {@code message} with the byte array using the given {@code schema}. */ public static <T> void mergeFrom(byte[] data, T message, Schema<T> schema, boolean numeric) throws IOException { mergeFrom(data, 0, data.length, message, schema, numeric); }
/** * 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); }
@Override public byte[] serialize(final T instance) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonIOUtil.writeTo(out, instance, writeSchema, false); return out.toByteArray(); }
/** * 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(); } }
/** * Parses the {@code messages} from the stream using the given {@code schema}. * * 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(); } }
/** * 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(); } }
/** * 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, boolean numeric) throws IOException { return newPipe(data, 0, data.length, numeric); }
/** * Parses the {@code messages} from the reader using the given {@code schema}. */ public static <T> List<T> parseListFrom(Reader reader, Schema<T> schema, boolean numeric) throws IOException { final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(reader); try { return parseListFrom(parser, schema, numeric); } finally { parser.close(); } }
/** * Serializes the {@code messages} into the writer using the given schema. */ public static <T> void writeListTo(Writer writer, List<T> messages, Schema<T> schema, boolean numeric) throws IOException { final JsonGenerator generator = DEFAULT_JSON_FACTORY.createJsonGenerator(writer); try { writeListTo(generator, messages, schema, numeric); } finally { generator.close(); } }
/** * 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)); }
/** * Merges the {@code message} from the {@link InputStream} using the * given {@code schema}. * * 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(); } }
/** * 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(); } }
/** * 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(); } }
/** * 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(); } }
/** * Creates a json pipe from a {@link Reader}. */ public static Pipe newPipe(Reader reader, boolean numeric) throws IOException { return newPipe(DEFAULT_JSON_FACTORY.createJsonParser(reader), numeric); }
/** * Parses the {@code messages} from the stream using the given {@code schema}. * * 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(); } }
/** * 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_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(); } }
/** * 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 = newJsonParser(in, context.allocReadIOBuffer(), 0, 0, true, context); //final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(in); try { mergeFrom(parser, message, schema, numeric); } finally { parser.close(); } }