Examples of BinaryEncoder


Examples of co.cask.cdap.common.io.BinaryEncoder

  }

  @Override
  public byte[] encode(KeyIdentifier keyIdentifier) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Encoder encoder = new BinaryEncoder(bos);

    encoder.writeInt(KeyIdentifier.Schemas.getVersion());
    DatumWriter<KeyIdentifier> writer = writerFactory.create(KEY_IDENTIFIER_TYPE,
                                                             KeyIdentifier.Schemas.getCurrentSchema());
    writer.encode(keyIdentifier, encoder);
    return bos.toByteArray();
  }
View Full Code Here

Examples of co.cask.tephra.snapshot.BinaryEncoder

  //--------- helpers to encode or decode the transaction state --------------

  @Override
  public void encode(OutputStream out, TransactionSnapshot snapshot) {
    BinaryEncoder encoder = new BinaryEncoder(out);
    try {
      encoder.writeLong(snapshot.getTimestamp());
      encoder.writeLong(snapshot.getReadPointer());
      encoder.writeLong(snapshot.getWritePointer());
      // supporting old versions of codecs
      encodeObsoleteAttributes(encoder);
      encodeInvalid(encoder, snapshot.getInvalid());
      encodeInProgress(encoder, snapshot.getInProgress());
      encodeChangeSets(encoder, snapshot.getCommittingChangeSets());
View Full Code Here

Examples of co.cask.tigon.io.BinaryEncoder

  @Override
  public void emit(T data, Map<String, Object> partitions) {
    try {
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      output.write(schemaHash);
      writer.encode(data, new BinaryEncoder(output));
      queueProducer.enqueue(new QueueEntry(Maps.transformValues(partitions, PARTITION_MAP_TRANSFORMER),
                                           output.toByteArray()));
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    // If not cached, get the default Java value by encoding the default JSON
    // value and then decoding it:
    if (defaultValue == null)
      try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(baos, null);
        ResolvingGrammarGenerator.encode(encoder, field.schema(), json);
        encoder.flush();
        BinaryDecoder decoder =
          DecoderFactory.get().binaryDecoder(baos.toByteArray(), null);
        defaultValue =
          createDatumReader(field.schema()).read(null, decoder);
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

                                 DatumWriter<Object> writer,
                                 DatumReader<Object> reader)
    throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.setSchema(schema);
    writer.write(datum, new BinaryEncoder(out));
    byte[] data = out.toByteArray();

    reader.setSchema(schema);
       
    Object decoded =
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

      ("{\"type\":\"enum\",\"name\":\"E\",\"symbols\":[\"X\",\"Y\"]}");
    Schema expected = Schema.parse
      ("{\"type\":\"enum\",\"name\":\"E\",\"symbols\":[\"Y\",\"Z\"]}");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DatumWriter<Object> writer = new GenericDatumWriter<Object>(actual);
    Encoder encoder = new BinaryEncoder(out);
    writer.write(new GenericData.EnumSymbol("Y"), encoder);
    writer.write(new GenericData.EnumSymbol("X"), encoder);
    byte[] data = out.toByteArray();
    Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(
        data, null);
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

  private static <T> byte[] render(T datum, Schema schema,
                               DatumWriter<T> writer)
    throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.setSchema(schema);
    writer.write(datum, new BinaryEncoder(out));
    return out.toByteArray();
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    int numObjects = Integer.parseInt(args[2]);
   
    FileOutputStream out = new FileOutputStream(outputFile, false);
    DatumWriter<Object> dout = new GenericDatumWriter<Object>();
    dout.setSchema(sch);
    Encoder vout = new BinaryEncoder(out);
    vout.writeLong(numObjects); // metadata:the count of objects in the file
   
    for (Object datum : new RandomData(sch, numObjects)) {
      dout.write(datum, bufOut);
      blockCount++;
      if (buffer.size() >= SYNC_INTERVAL) {
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

  }

  @Test
  public void test() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Encoder e = new ValidatingEncoder(schema, new BinaryEncoder(baos));
   
    ResolvingGrammarGenerator.encode(e, schema, data);
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    checkReadWrite(object, ReflectData.get().getSchema(object.getClass()));
  }
  void checkReadWrite(Object object, Schema s) throws Exception {
    ReflectDatumWriter<Object> writer = new ReflectDatumWriter<Object>(s);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.write(object, new BinaryEncoder(out));
    ReflectDatumReader<Object> reader = new ReflectDatumReader<Object>(s);
    Object after =
      reader.read(null, DecoderFactory.defaultFactory().createBinaryDecoder(
          out.toByteArray(), null));
    assertEquals(object, after);
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.