Package org.apache.avro.io

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();
      if (messageName.equals(""))                 // a handshake ping
        return handshake;
      Message rm = remote.getMessages().get(messageName);
      if (rm == null)
        throw new AvroRuntimeException("No such remote message: "+messageName);
View Full Code Here


   @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

    writer.write( message, encoder );
    encoder.flush();

    ByteArrayInputStream inputStream = new ByteArrayInputStream( out.toByteArray() );
    Decoder decoder = DecoderFactory.get().binaryDecoder( inputStream, null );
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>( messageSchema );
    while ( true ) {
      try {
        GenericRecord result = reader.read( null, decoder );
        System.out.println( result );
View Full Code Here

    final ByteArrayInputStream inputStream = new ByteArrayInputStream( data );
    final int majorVersion = inputStream.read();
    final int minorVersion = inputStream.read();
    final Protocol protocol = protocols.getProtocol( majorVersion, minorVersion );

    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

   * in the hbase row
   */
  protected T
  readValue(byte[] data, Schema schema, AvroFormat format, int offset, int length) throws AvroBaseException {
    try {
      Decoder d;
      switch (format) {
        case JSON:
          d = decoderFactory.jsonDecoder(schema, new String(data, UTF8));
          break;
        case BINARY:
View Full Code Here

    Schema schema = Schema.parse(objectInput.readUTF());
    // length
    byte[] bytes = new byte[objectInput.readInt()];
    // bytes
    objectInput.readFully(bytes);
    Decoder d = decoderFactory.binaryDecoder(bytes, 0, bytes.length, null);
    SpecificDatumReader<T> sdr = new SpecificDatumReader<T>(schema);
    value = sdr.read(null, d);
  }
View Full Code Here

        schemaCache.put(hash, schema);
        hashCache.put(schema, hash);
      }
      try {
        DecoderFactory decoderFactory = new DecoderFactory();
        Decoder d;
        switch (format) {
          case JSON:
            d = decoderFactory.jsonDecoder(schema, is);
            break;
          case BINARY:
View Full Code Here

   * @throws IOException on I/O error.
   */
  public static Set<KijiUser> deserializeKijiUsers(byte[] bytes) throws IOException {
    SpecificDatumReader<SecurityUserList> reader =
        new SpecificDatumReader<SecurityUserList>(SecurityUserList.SCHEMA$);
    Decoder decoder = DecoderFactory.get().binaryDecoder(bytes, null);
    SecurityUserList securityUserList = reader.read(null, decoder);

    Set<KijiUser> result = new HashSet<KijiUser>();
    for (KijiUserRecord userRecord : securityUserList.getUsers()) {
      result.add(KijiUser.fromName(userRecord.getName()));
View Full Code Here

   * @return Decoded Avro schema entry.
   * @throws IOException on I/O error.
   */
  public static SchemaTableEntry decodeSchemaEntry(final byte[] bytes) throws IOException {
    final SchemaTableEntry entry = new SchemaTableEntry();
    final Decoder decoder =
        DECODER_FACTORY.directBinaryDecoder(new ByteArrayInputStream(bytes), null);
    return SCHEMA_ENTRY_READER.read(entry, decoder);
  }
View Full Code Here

      LOG.debug(
          "Decode datum {} whose writer is {} with reader {}.",
          datum, writerSchema, readerSchema);
      final byte[] bytes = baos.toByteArray();
      final Decoder decoder = DecoderFactory.get().resolvingDecoder(
          writerSchema, readerSchema,
          DecoderFactory.get().binaryDecoder(bytes, null));
      final DatumReader<Object> datumReader = new GenericDatumReader<Object>(readerSchema);
      final Object decodedDatum = datumReader.read(null, decoder);
View Full Code Here

TOP

Related Classes of org.apache.avro.io.Decoder

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.