Package org.apache.avro.io

Examples of org.apache.avro.io.BinaryDecoder


     * @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(bytes.array(),bytes.position()+bytes.arrayOffset(),bytes.remaining(), 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(bytes.array(),bytes.position()+bytes.arrayOffset(), bytes.remaining(), 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

        this.schema = schema;
    }

    @Override
    public T decode(IoBuffer input) {
        BinaryDecoder binaryDecoder = DecoderFactory.get().binaryDecoder(input.array(), null);
        ReflectDatumReader<T> reader = new ReflectDatumReader<T>(schema);
        T result = null;
        try {
            result = reader.read(null, binaryDecoder);
        }catch (IOException ioEx) {
View Full Code Here

    public Schema getAvroSchema() { return _avroSchema; }

    public static BinaryDecoder decoder(InputStream in)
    {
        SoftReference<BinaryDecoder> ref = decoderRecycler.get();
        BinaryDecoder prev = (ref == null) ? null : ref.get();
       
        if (prev != null) {
            return DECODER_FACTORY.binaryDecoder(in, prev);
        }
        prev = DECODER_FACTORY.binaryDecoder(in, null);
View Full Code Here

    }

    public static BinaryDecoder decoder(byte[] buffer, int offset, int len)
    {
        SoftReference<BinaryDecoder> ref = decoderRecycler.get();
        BinaryDecoder prev = (ref == null) ? null : ref.get();
       
        if (prev != null) {
            return DECODER_FACTORY.binaryDecoder(buffer, offset, len, prev);
        }
        prev = DECODER_FACTORY.binaryDecoder(buffer, offset, len, null);
View Full Code Here

      byte [] bytes = new byte[buffer.limit()];
      buffer.get(bytes);
      in = new ByteArrayInputStream(bytes);
    }

    BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(in, null);
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>(logSchema.getAvroSchema());
    try {
      return reader.read(null, decoder);
    } catch (IOException e) {
      throw Throwables.propagate(e);
View Full Code Here

          break;
        case RECORD:
          SpecificDatumReader reader = new SpecificDatumReader(field.schema());
          byte[] val = entry.getValue().get();
          // TODO reuse decoder
          BinaryDecoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(val, null);
          persistent.put(field.pos(), reader.read(null, decoder));
          break;
        default:
          persistent.put(field.pos(), fromBytes(field.schema(), entry.getValue().get()));
      }
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.