@Override protected Encoder newEncoder(ByteArrayOutputStream out) throws IOException { return encoder_factory.validatingEncoder(schema, super.newEncoder(out)); } }
@Test public void test() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); EncoderFactory factory = EncoderFactory.get(); Encoder e = factory.validatingEncoder(schema, factory.binaryEncoder(baos, null)); ResolvingGrammarGenerator.encode(e, schema, data); e.flush(); }
@Test public void testValidatingEncoderInit() throws IOException { Schema s = Schema.parse("\"int\""); OutputStream out = new ByteArrayOutputStream(); Encoder e = factory.directBinaryEncoder(out, null); factory.validatingEncoder(s, e).configure(e); }
public static void checkBinaryJson(String json) throws Exception { Object node = Json.parseJson(json); ByteArrayOutputStream out = new ByteArrayOutputStream(); DatumWriter<Object> writer = new Json.ObjectWriter(); Encoder encoder = EncoderFactory.get().binaryEncoder(out, null); encoder = EncoderFactory.get().validatingEncoder(Json.SCHEMA, encoder); writer.write(node, encoder); encoder.flush(); byte[] bytes = out.toByteArray(); DatumReader<Object> reader = new Json.ObjectReader(); Decoder decoder = DecoderFactory.get().binaryDecoder(bytes, null); decoder = DecoderFactory.get().validatingDecoder(Json.SCHEMA, decoder); Object decoded = reader.read(null, decoder); assertEquals("Decoded json does not match.", Json.toString(node), Json.toString(decoded)); }
public static byte[] make(Schema sc, String calls, Object[] values, Encoding encoding) throws IOException { EncoderFactory factory = EncoderFactory.get(); ByteArrayOutputStream ba = new ByteArrayOutputStream(); Encoder bvo = null; switch (encoding) { case BINARY: bvo = factory.binaryEncoder(ba, null); break; case BLOCKING_BINARY: bvo = factory.blockingBinaryEncoder(ba, null); break; case JSON: bvo = factory.jsonEncoder(sc, ba); break; } Encoder vo = factory.validatingEncoder(sc, bvo); generate(vo, calls, values); vo.flush(); return ba.toByteArray(); }