Package org.apache.avro.io

Examples of org.apache.avro.io.BinaryDecoder


    transaction.begin();
    Event event = ch.take();
    Assert.assertNotNull(event);

    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>(schema);
    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(event.getBody(), null);
    GenericRecord recordFromEvent = reader.read(null, decoder);
    Assert.assertEquals(msg, recordFromEvent.get("message").toString());

    Map<String, String> hdrs = event.getHeaders();
View Full Code Here


    Assert.assertNotNull(event);

    Schema schema = ReflectData.get().getSchema(appEvent.getClass());

    ReflectDatumReader<AppEvent> reader = new ReflectDatumReader<AppEvent>(AppEvent.class);
    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(event.getBody(), null);
    AppEvent recordFromEvent = reader.read(null, decoder);
    Assert.assertEquals(msg, recordFromEvent.getMessage());

    Map<String, String> hdrs = event.getHeaders();
View Full Code Here

     * @param ob An empty object to deserialize into (must not be null).
     * @throws IOException
     */
    public static <T extends SpecificRecord> T deserialize(Schema writer, ByteBuffer bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(ByteBufferUtil.getArray(bytes), null);
        SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
        reader.setExpected(ob.getSchema());
        return reader.read(ob, dec);
    }
View Full Code Here

     * @param bytes Array to deserialize from
     * @throws IOException
     */
    public static <T extends SpecificRecord> T deserializeWithSchema(ByteBuffer bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(ByteBufferUtil.getArray(bytes), null);
        Schema writer = Schema.parse(dec.readString(new Utf8()).toString());
        SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
        reader.setExpected(ob.getSchema());
        return reader.read(ob, dec);
    }
View Full Code Here

     *
     * @throws IOException if deserialization failed
     */
    public static <T extends SpecificRecord> T deserializeAvro(org.apache.avro.Schema writer, ByteBuffer bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(ByteBufferUtil.getArray(bytes), null);
        SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
        reader.setExpected(ob.getSchema());
        return reader.read(ob, dec);
    }
View Full Code Here

     *
     * @throws IOException if deserialization failed
     */
    public static <T extends SpecificRecord> T deserializeAvro(org.apache.avro.Schema writer, ByteBuffer bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(ByteBufferUtil.getArray(bytes), null);
        SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
        reader.setExpected(ob.getSchema());
        return reader.read(ob, dec);
    }
View Full Code Here

    }
    InputStream input = Util.fileOrStdin(inputFile, stdin);

    try {
      DatumReader<Object> reader = new GenericDatumReader<Object>(schema);
      BinaryDecoder binaryDecoder =
        DecoderFactory.get().binaryDecoder(input, null);
      DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema);
      JsonEncoder jsonEncoder = EncoderFactory.get().jsonEncoder(schema, out, !noPretty);
      Object datum = null;
      while (!binaryDecoder.isEnd()){
        datum = reader.read(datum, binaryDecoder);
        writer.write(datum, jsonEncoder);
        jsonEncoder.flush();
      }
      out.println();
View Full Code Here

    }
    InputStream input = Util.fileOrStdin(inputFile, stdin);

    try {
      DatumReader<Object> reader = new GenericDatumReader<Object>(schema);
      BinaryDecoder binaryDecoder =
        DecoderFactory.get().binaryDecoder(input, null);
      DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema);
      JsonEncoder jsonEncoder = EncoderFactory.get().jsonEncoder(schema, out, !noPretty);
      Object datum = null;
      while (!binaryDecoder.isEnd()){
        datum = reader.read(datum, binaryDecoder);
        writer.write(datum, jsonEncoder);
        jsonEncoder.flush();
      }
      out.println();
View Full Code Here

      try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(baos, null);
        ResolvingGrammarGenerator.encode(encoder, field.schema(), json);
        encoder.flush();
        BinaryDecoder decoder =
          DecoderFactory.get().binaryDecoder(baos.toByteArray(), null);
        defaultValue =
          createDatumReader(field.schema()).read(null, decoder);

        defaultValueCache.put(field, defaultValue);
View Full Code Here

    public static GenericRecord deserialize(Schema schema, byte[] array)
            throws IOException {
        GenericDatumReader<GenericRecord> serveReader = new GenericDatumReader<GenericRecord>(schema);
        return serveReader.read(null,
                                new BinaryDecoder(new ByteArrayInputStream(array)));
    }
View Full Code Here

TOP

Related Classes of org.apache.avro.io.BinaryDecoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.