Package org.apache.avro.io

Examples of org.apache.avro.io.BinaryDecoder$ByteArrayByteSource


     *
     * @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

    Text currentFam = null;
    int currentPos = 0;
    Schema currentSchema = null;
    Field currentField = null;

    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(new byte[0], null);

    while (iter.hasNext()) {
      Entry<Key,Value> entry = iter.next();

      if (row == null) {
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

 
  /** Writes a request message and reads a response or error message. */
  public synchronized Object request(String messageName, Object request)
    throws Exception {
    Transceiver t = getTransceiver();
    BinaryDecoder in = null;
    Message m;
    RPCContext context = new RPCContext();
    do {
      ByteBufferOutputStream bbo = new ByteBufferOutputStream();
      //safe to use encoder because this is synchronized
      BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder);
     
      // use local protocol to write request
      m = getLocal().getMessages().get(messageName);
      if (m == null)
        throw new AvroRuntimeException("Not a local message: "+messageName);
      context.setMessage(m);
   
      writeRequest(m.getRequest(), request, out); // write request payload
     
      out.flush();
      List<ByteBuffer> payload = bbo.getBufferList();
     
      writeHandshake(out);                       // prepend handshake if needed
     
      context.setRequestPayload(payload);
      for (RPCPlugin plugin : rpcMetaPlugins) {
        plugin.clientSendRequest(context);        // get meta-data from plugins
      }
      META_WRITER.write(context.requestCallMeta(), out);

      out.writeString(m.getName());               // write message name

      out.flush();
      bbo.append(payload);
     
      List<ByteBuffer> requestBytes = bbo.getBufferList();

      if (m.isOneWay() && t.isConnected()) {      // send one-way message
        t.writeBuffers(requestBytes);
       
        return null;
      } else {                                    // two-way message
        List<ByteBuffer> response = t.transceive(requestBytes);
        ByteBufferInputStream bbi = new ByteBufferInputStream(response);
        in = DecoderFactory.get().binaryDecoder(bbi, in);
      }
    } while (!readHandshake(in));

    // use remote protocol to read response
    Message rm = remote.getMessages().get(messageName);
    if (rm == null)
      throw new AvroRuntimeException("Not a remote message: "+messageName);

    if ((m.isOneWay() != rm.isOneWay()) && t.isConnected())
      throw new AvroRuntimeException("Not both one-way messages: "+messageName);

    if (m.isOneWay() && t.isConnected()) return null; // one-way w/ handshake
       
    context.setResponseCallMeta(META_READER.read(null, in));
   
    if (!in.readBoolean()) {                      // no error
      Object response = readResponse(rm.getResponse(), in);
      context.setResponse(response);
      for (RPCPlugin plugin : rpcMetaPlugins) {
        plugin.clientReceiveResponse(context);
      }
View Full Code Here

    out.writeInt(0);                              // empty metadata
    out.writeString("");                          // bogus message name
    List<ByteBuffer> response =
      getTransceiver().transceive(bbo.getBufferList());
    ByteBufferInputStream bbi = new ByteBufferInputStream(response);
    BinaryDecoder in =
      DecoderFactory.get().binaryDecoder(bbi, null);
    readHandshake(in);
    return this.remote;
  }
View Full Code Here

    Text currentFam = null;
    int currentPos = 0;
    Schema currentSchema = null;
    Field currentField = null;

    BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(new byte[0], null);

    while (iter.hasNext()) {
      Entry<Key,Value> entry = iter.next();

      if (row == null) {
View Full Code Here

    AvroEventDeserializer.Builder desBuilder =
        new AvroEventDeserializer.Builder();
    EventDeserializer deserializer = desBuilder.build(new Context(),
        new ResettableFileInputStream(tempFile, tracker));

    BinaryDecoder decoder = null;
    DatumReader<GenericRecord> reader =
        new GenericDatumReader<GenericRecord>(schema);

    decoder = DecoderFactory.get().binaryDecoder(
        deserializer.readEvent().getBody(), decoder);
View Full Code Here

    record.x = 5;
    record.y = 10;
    writer.write(record, new BinaryEncoder(out));
    ReflectDatumReader reader = new ReflectDatumReader(schm, prefix);
    Object decoded =
      reader.read(null, new BinaryDecoder
                  (new ByteArrayInputStream(out.toByteArray())));
    assertEquals(record, decoded);
  }
View Full Code Here

TOP

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

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.