Package org.apache.avro.io

Examples of org.apache.avro.io.DecoderFactory


      be.flush();
      fos.close();
    }
    {
      FileInputStream fis = new FileInputStream(file);
      DecoderFactory factory = new DecoderFactory();
      BinaryDecoder bd = factory.binaryDecoder(fis, null);
      SpecificDatumReader<User> sdr = new SpecificDatumReader<User>(User.class);
      User loaded = sdr.read(null, bd);
      fis.close();
      assertEquals(saved, loaded);
      assertEquals("Sam", loaded.firstName.toString());
View Full Code Here


      be.flush();
      fos.close();
    }
    {
      FileInputStream fis = new FileInputStream(file);
      DecoderFactory factory = new DecoderFactory();
      BinaryDecoder bd = factory.binaryDecoder(fis, null);
      SpecificDatumReader<User> sdr = new SpecificDatumReader<User>(User.class);
      User loaded = sdr.read(null, bd);
      fis.close();
      assertEquals(saved, loaded);
      assertEquals(null, loaded.location);
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:
          default:
            d = decoderFactory.binaryDecoder(is, null);
            break;
        }
        // Read the data
        SpecificDatumReader<T> sdr = new SpecificDatumReader<T>(schema);
        sdr.setExpected(actualSchema);
View Full Code Here

        }
        Preconditions.checkNotNull(mSchema);

        // Create the Avro record to write.
        GenericDatumReader<Object> reader = new GenericDatumReader<Object>(mSchema);
        Object datum = reader.read(null, new DecoderFactory().jsonDecoder(mSchema, mJsonValue));

        // Write the put.
        if (-1 == mTimestamp) {
          writer.put(entityId, column.getFamily(), column.getQualifier(), datum);
        } else {
View Full Code Here

              int len = dis.readInt();
              if (len > valuebytes.length) {
                valuebytes = new byte[len];
              }
              dis.readFully(valuebytes, 0, len);
              DecoderFactory decoderFactory = new DecoderFactory();
              Decoder d = decoderFactory.binaryDecoder(new ByteArrayInputStream(valuebytes, 0, len), null);
              // Read the data
              SpecificDatumReader<Beacon> sdr = new SpecificDatumReader<Beacon>(writerSchema, Beacon.SCHEMA$);
              Beacon read = sdr.read(null, d);
              beaconFAB.put(row, read);
            }
View Full Code Here

   * @param reader
   *          The DatumReader that will decode the byte array.
   * @return The Avro entity.
   */
  public static <T> T readAvroEntity(byte[] bytes, DatumReader<T> reader) {
    Decoder decoder = new DecoderFactory().binaryDecoder(bytes, null);
    return AvroUtils.<T> readAvroEntity(decoder, reader);
  }
View Full Code Here

  private final InputStream in;
  private final DataInputStream dataIn;

  public ColumnDecoder(InputStream in) {
    this.in = in;
    this.wrappedDecoder = new DecoderFactory().binaryDecoder(in, null);
    this.dataIn = new DataInputStream(in);
  }
View Full Code Here

   * @param reader
   *          The DatumReader that will decode the byte array.
   * @return The Avro entity.
   */
  public static <T> T readAvroEntity(byte[] bytes, DatumReader<T> reader) {
    Decoder decoder = new DecoderFactory().binaryDecoder(bytes, null);
    return AvroUtils.<T> readAvroEntity(decoder, reader);
  }
View Full Code Here

  private final InputStream in;
  private final DataInputStream dataIn;

  public ColumnDecoder(InputStream in) {
    this.in = in;
    this.wrappedDecoder = new DecoderFactory().binaryDecoder(in, null);
    this.dataIn = new DataInputStream(in);
  }
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

TOP

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

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.