Examples of BinaryEncoder


Examples of org.apache.avro.io.BinaryEncoder

    Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
    ReflectDatumWriter<AnotherSampleRecord> writer =
      new ReflectDatumWriter<AnotherSampleRecord>(schm);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // keep record.a null and see if that works
    BinaryEncoder e = new BinaryEncoder(out);
    AnotherSampleRecord a = new AnotherSampleRecord();
    writer.write(a, e);
    AnotherSampleRecord b = new AnotherSampleRecord(10);
    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);
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

     */
    public List<ByteBuffer> getBytes()
      throws Exception {
      if (requestBytes == null) {
        ByteBufferOutputStream bbo = new ByteBufferOutputStream();
        BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder);

        // use local protocol to write request
        Message m = getMessage();
        context.setMessage(m);

        writeRequest(m.getRequest(), request, out); // write request payload

        out.flush();
        List<ByteBuffer> payload = bbo.getBufferList();

        writeHandshake(out);                     // prepend handshake if needed

        context.setRequestPayload(payload);
        for (RPCPlugin plugin : rpcMetaPlugins) {
          plugin.clientSendRequest(context);      // get meta-data from plugins
        }
        META_WRITER.write(context.requestCallMeta(), out);

        out.writeString(m.getName());             // write message name

        out.flush();
        bbo.append(payload);

        requestBytes = bbo.getBufferList();
      }
      return requestBytes;
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

   */
  private Event makeEvent(GenericData.Record record, Schema schema) throws IOException {
    GenericDatumWriter<GenericRecord> datumWriter =
        new GenericDatumWriter<GenericRecord>(schema);
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    BinaryEncoder encoder = new BinaryEncoder(outBytes);

    datumWriter.write(record, encoder);
    return new EventImpl(outBytes.toByteArray());
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

  public AvroOutputElementImpl(FlowElementContext ctxt, Schema outputSchema) {
    super(ctxt);
    mDatumWriter = new GenericDatumWriter<GenericRecord>(outputSchema);
    mOutputBytes = new ByteArrayOutputStream();
    mEncoder = new BinaryEncoder(mOutputBytes);
    mOutputSchema = outputSchema;
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    mFlumeInputFields = SQLStatement.distinctFields(mInputFields);
    assert mFlumeInputFields.size() == mOutputFields.size();

    mDatumWriter = new GenericDatumWriter<GenericRecord>(outputSchema);
    mOutputBytes = new ByteArrayOutputStream();
    mEncoder = new BinaryEncoder(mOutputBytes);
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

   }

   @Override
   protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException {
      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(estimatedSize);
      Encoder encoder = new BinaryEncoder(baos);
      objectToBuffer(o, encoder);
      return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
   }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

  }

  protected Encoder createEncoder() throws IOException {
    switch(codecType) {
      case BINARY:
        return new BinaryEncoder(getOrCreateOutputStream());
      case JSON:
        return new JsonEncoder(schema, getOrCreateOutputStream());
    }
    return null;
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

            }
            break;
          case RECORD:
            SpecificDatumWriter writer = new SpecificDatumWriter(field.schema());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            BinaryEncoder encoder = new BinaryEncoder(os);
            writer.write(o, encoder);
            encoder.flush();
            m.put(col.getFirst(), col.getSecond(), new Value(os.toByteArray()));
            break;
          default:
            m.put(col.getFirst(), col.getSecond(), new Value(toBytes(o)));
            count++;
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    encoder.flush();
  }

  //@Override
  public void open(OutputStream out) throws IOException {
    encoder = new BinaryEncoder(out);
  }
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

   */
  public static<T extends PersistentBase> void serialize(OutputStream os,
      PersistentDatumWriter<T> datumWriter, Schema schema, Object object)
      throws IOException {

    BinaryEncoder encoder = new BinaryEncoder(os);
    datumWriter.write(schema, object, encoder);
    encoder.flush();
  }
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.