Examples of Decoder


Examples of org.apache.avro.io.Decoder

    writer.write(b, e);
    e.flush();
    ReflectDatumReader<AnotherSampleRecord> reader =
      new ReflectDatumReader<AnotherSampleRecord>(schm);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Decoder d = DecoderFactory.defaultFactory().createBinaryDecoder(in, null);
    AnotherSampleRecord decoded = reader.read(null, d);
    assertEquals(a, decoded);
    decoded = reader.read(null, d);
    assertEquals(b, decoded);
  }
View Full Code Here

Examples of org.apache.avro.io.Decoder

  /** Called by a server to deserialize a request, compute and serialize a
   * response or error.  Transciever is used by connection-based servers to
   * track handshake status of connection. */
  public List<ByteBuffer> respond(List<ByteBuffer> buffers,
                                  Transceiver connection) throws IOException {
    Decoder in = DecoderFactory.get().binaryDecoder(
        new ByteBufferInputStream(buffers), null);
    ByteBufferOutputStream bbo = new ByteBufferOutputStream();
    BinaryEncoder out = EncoderFactory.get().binaryEncoder(bbo, null);
    Exception error = null;
    RPCContext context = new RPCContext();
    List<ByteBuffer> payload = null;
    List<ByteBuffer> handshake = null;
    boolean wasConnected = connection != null && connection.isConnected();
    try {
      Protocol remote = handshake(in, out, connection);
      out.flush();
      if (remote == null)                        // handshake failed
        return bbo.getBufferList();
      handshake = bbo.getBufferList();
     
      // read request using remote protocol specification
      context.setRequestCallMeta(META_READER.read(null, in));
      String messageName = in.readString(null).toString();
      Message rm = remote.getMessages().get(messageName);
      if (rm == null)
        throw new AvroRuntimeException("No such remote message: "+messageName);
      Message m = getLocal().getMessages().get(messageName);
      if (m == null)
View Full Code Here

Examples of org.apache.avro.io.Decoder

        }
        return output.toByteArray();
    }

    public T toObject(byte[] bytes) {
        Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
        SpecificDatumReader<T> reader = null;
        try {
            reader = new SpecificDatumReader<T>(clazz);
            return reader.read(null, decoder);
        } catch(IOException e) {
View Full Code Here

Examples of org.apache.avro.io.Decoder

        }
        return output.toByteArray();
    }

    public Object toObject(byte[] bytes) {
        Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
        GenericDatumReader<Object> reader = null;
        try {
            reader = new GenericDatumReader<Object>(typeDef);
            return reader.read(null, decoder);
        } catch(IOException e) {
View Full Code Here

Examples of org.apache.avro.io.Decoder

        }
        return output.toByteArray();
    }

    public T toObject(byte[] bytes) {
        Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
        ReflectDatumReader<T> reader = null;
        try {
            reader = new ReflectDatumReader<T>(clazz);
            return reader.read(null, decoder);
        } catch(IOException e) {
View Full Code Here

Examples of org.apache.avro.io.Decoder

        Schema typeDefWriter = Schema.parse(typeDefVersions.get(version));

        byte[] dataBytes = new byte[bytes.length - 1];
        System.arraycopy(bytes, 1, dataBytes, 0, bytes.length - 1);
        Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(dataBytes, null);
        GenericDatumReader<Object> reader = null;
        try {
            reader = new GenericDatumReader<Object>(typeDefWriter, typeDef);
            // writer's schema
            reader.setSchema(typeDefWriter);
View Full Code Here

Examples of org.apache.avro.io.Decoder

   @Override
   public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException {
      DecoderFactory factory = new DecoderFactory(); // TODO: Could this be cached?
      InputStream is = new ByteArrayInputStream(buf, offset, length);
      Decoder decoder = factory.createBinaryDecoder(is, null);
      return objectFromByteBuffer(decoder);
   }
View Full Code Here

Examples of org.apache.avro.io.Decoder

    writer.write(b, e);
    e.flush();
    ReflectDatumReader<AnotherSampleRecord> reader =
      new ReflectDatumReader<AnotherSampleRecord>(schm);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Decoder d = DecoderFactory.defaultFactory().createBinaryDecoder(in, null);
    AnotherSampleRecord decoded = reader.read(null, d);
    assertEquals(a, decoded);
    decoded = reader.read(null, d);
    assertEquals(b, decoded);
  }
View Full Code Here

Examples of org.apache.avro.io.Decoder

  }

  public List<GenericRecord> convert(InputStream in) throws IOException
  {

    Decoder inputDecoder = (_inputFormat == AvroFormat.BINARY) ?
        DecoderFactory.defaultFactory().createBinaryDecoder(in, null) :
        (AvroFormat.JSON == _inputFormat) ?
            new JsonDecoder(_inputSchema, in) :
            null;
View Full Code Here

Examples of org.apache.avro.io.Decoder

                + "." + AvroSerializationProvider.getMinorVersion()
        );
      }
    }

    Decoder decoder = DecoderFactory.get().binaryDecoder( inputStream, null );
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>( protocol.getType( "Message" ) );
    GenericRecord result;
    try {
      result = reader.read( null, decoder );
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.