Package org.apache.avro.io

Examples of org.apache.avro.io.BinaryDecoder


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


  }
 
  public static <V> V fromBytes(byte[] bytes, Class<V> cls) throws Exception{
       SpecificDatumReader<V> reader = new SpecificDatumReader<V>(cls);
   
    BinaryDecoder binDecoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
    V val = cls.newInstance();
    reader.read(val, binDecoder);
   
    return val;
  }
View Full Code Here

    dump(bs);
    Assert.assertEquals(12, bs.length);

    ByteArrayInputStream bais = new ByteArrayInputStream(bs);
    ReflectDatumReader<A> reader = new ReflectDatumReader<A>(schm);
    BinaryDecoder dec = (new DecoderFactory()).createBinaryDecoder(bais, null);
    A decoded = reader.read(null, dec);
    LOG.info(decoded);
  }
View Full Code Here

    Assert.assertEquals(60, bs.length);

    ByteArrayInputStream bais = new ByteArrayInputStream(bs);
    ReflectDatumReader<EventImpl> reader = new ReflectDatumReader<EventImpl>(
        schm);
    BinaryDecoder dec = (new DecoderFactory()).createBinaryDecoder(bais, null);
    EventImpl decoded = reader.read(null, dec);
    // EventImpl decoded = reader.read(null, new BinaryDecoder(bais));
    LOG.info(decoded);
  }
View Full Code Here

    // System.out.println("length = "+data.length);

    reader.setSchema(schema);
       
    Object decoded =
      reader.read(null, new BinaryDecoder(new ByteArrayInputStream(data)));
     
    // System.out.println(GenericData.toString(datum));
    // System.out.println(GenericData.toString(decoded));
    assertEquals("Decoded data does not match.", datum, decoded);
  }
View Full Code Here

    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, new BinaryDecoder(new ByteArrayInputStream(new byte[0])));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here

     
      List<ByteBuffer> response =                 // transceive
        getTransceiver().transceive(bbo.getBufferList());
     
      ByteBufferInputStream bbi = new ByteBufferInputStream(response);
      in = new BinaryDecoder(bbi);
      if (!established)                           // if not established
        readHandshake(in);                        // process handshake
    } while (!established);

    // use remote protocol to read response
View Full Code Here

    long length = in.length();
    in.seek(length-4);
    int footerSize=(in.read()<<24)+(in.read()<<16)+(in.read()<<8)+in.read();
    in.seek(length-footerSize);
    this.vin = new BinaryDecoder(in);
    long l = vin.readMapStart();
    if (l > 0) {
      do {
        for (long i = 0; i < l; i++) {
          String key = vin.readString(null).toString();
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, byte[] bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(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(byte[] bytes, T ob) throws IOException
    {
        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(bytes, null);
        Schema writer = Schema.parse(dec.readString(new Utf8()).toString());
        SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
        reader.setExpected(ob.getSchema());
        return new SpecificDatumReader<T>(writer).read(ob, dec);
    }
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.