Package org.apache.avro.io

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


    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

          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

        reader = new SpecificDatumReader(schema);    
        readerMap.put(schema.getFullName(), reader);
      }
     
      // initialize a decoder, possibly reusing previous one
      BinaryDecoder decoderFromCache = decoders.get();
      BinaryDecoder decoder=DecoderFactory.defaultFactory().
          createBinaryDecoder(val, decoderFromCache);
      // put in threadlocal cache if the initial get was empty
      if (decoderFromCache==null) {
        decoders.set(decoder);
      }
View Full Code Here

  }

  /** Writes a request message and reads a response or error message. */
  public Object request(String messageName, Object request)
    throws Exception {
    BinaryDecoder in = null;
    Message m;
    RPCContext context = new RPCContext();
    do {
      ByteBufferOutputStream bbo = new ByteBufferOutputStream();
      Encoder out = new BinaryEncoder(bbo);

      writeHandshake(out);                      // prepend handshake

      // 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);
     
      for (RPCPlugin plugin : rpcMetaPlugins) {
        plugin.clientSendRequest(context);
      }
     
      META_WRITER.write(context.requestCallMeta(), out);
      out.writeString(m.getName());       // write message name
      writeRequest(m.getRequest(), request, out); // write request payload
     
      List<ByteBuffer> response =                 // transceive
        getTransceiver().transceive(bbo.getBufferList());
     
      ByteBufferInputStream bbi = new ByteBufferInputStream(response);
      in = DecoderFactory.defaultFactory().createBinaryDecoder(bbi, in);
    } while (!readHandshake(in));

    // use remote protocol to read response
    m = getRemote().getMessages().get(messageName);
    if (m == null)
      throw new AvroRuntimeException("Not a remote message: "+messageName);
    context.setRequestCallMeta(META_READER.read(null, in));
   
    if (!in.readBoolean()) {                      // no error
      Object response = readResponse(m.getResponse(), in);
      context.setResponse(response);
      for (RPCPlugin plugin : rpcMetaPlugins) {
        plugin.clientReceiveResponse(context);
      }
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

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

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

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.