Examples of BinaryEncoder


Examples of org.apache.avro.io.BinaryEncoder

          //Count of all the events in the current transaction
          eventsInTransactionCount++;
          // Serialize the row
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          Encoder encoder = new BinaryEncoder(bos);
          GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(
              record.getSchema());
          writer.write(record, encoder);
          byte[] serializedValue = bos.toByteArray();
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    {
      try
      {
        // Serialize the row
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Encoder encoder = new BinaryEncoder(bos);
        GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(
            record.getSchema());
        writer.write(record, encoder);
        byte[] serializedValue = bos.toByteArray();
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    // Serialize the row
    byte[] serializedValue;
    try
    {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Encoder encoder = new BinaryEncoder(bos);
      GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(record.getSchema());
      writer.write(record, encoder);
      serializedValue = bos.toByteArray();
    }
    catch(IOException ex)
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    JsonGenerator jsonGenerator = (new JsonFactory()).createJsonGenerator(new OutputStreamWriter(out));
    if (AvroFormat.JSON == _outputFormat) jsonGenerator.useDefaultPrettyPrinter();

    List<GenericRecord> result = convert(in);
    Encoder outputEncoder = (AvroFormat.BINARY == _outputFormat) ?
        new BinaryEncoder(out) :
        new JsonEncoder(_outputSchema, jsonGenerator);

    GenericDatumWriter<GenericRecord> genericWriter = new GenericDatumWriter<GenericRecord>(_outputSchema);
    for (GenericRecord r: result)
    {
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

  {
    ConsumerCallbackResult result = ConsumerCallbackResult.SUCCESS;
    try
    {

      BinaryEncoder binEnc = _binEncoders.get(r.getSchema());
      if (null == binEnc)
      {
        binEnc = new BinaryEncoder(_out);
        _binEncoders.put(r.getSchema(), binEnc);
      }

      GenericDatumWriter<GenericRecord> datumWriter = binWriters.get(r.getSchema());
      if (null == datumWriter)
      {
        datumWriter = new GenericDatumWriter<GenericRecord>(r.getSchema());
        binWriters.put(r.getSchema(), datumWriter);
      }

      datumWriter.write(r, binEnc);
      binEnc.flush();
      _out.write('\n');
    }
    catch (RuntimeException re)
    {
      LOG.error("event dump error: " + re.getMessage(), re);
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    // Serialize the row
    byte[] serializedValue;
    try
    {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Encoder encoder = new BinaryEncoder(bos);
      GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(record.getSchema());
      writer.write(record, encoder);
      serializedValue = bos.toByteArray();
    }
    catch(IOException ex)
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    {
      GenericRecord r = new GenericData.Record(SOURCE1_SCHEMA);
      String s = RngUtils.randomString(rng.nextInt(100));
      r.put("s", s);
      ByteArrayOutputStream baos = new ByteArrayOutputStream(s.length() + 100);
      BinaryEncoder out = new BinaryEncoder(baos);
      try
      {
        writer.write(r, out);
        out.flush();

        result[i] = new DbusEventInfo(DbusOpcode.UPSERT, 1, (short)1, (short)1,
                                      System.nanoTime(),
                                      (short)1, SOURCE1_SCHEMAID,
                                      baos.toByteArray(), false, true);
View Full Code Here

Examples of org.apache.avro.io.BinaryEncoder

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write( AvroSerializationProvider.getMajorVersion() );
    out.write( AvroSerializationProvider.getMinorVersion() );
    Schema msgSchema = protocol.getType( "Message" );
    GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>( msgSchema );
    BinaryEncoder encoder = EncoderFactory.get().directBinaryEncoder( out, null );
    GenericRecord message = new GenericData.Record( msgSchema );
    message.put( "classReferences", classReferences );
    message.put( "operations", operations );
    operations = null;
    try {
      writer.write( message, encoder );
      encoder.flush();
    }
    catch (IOException e) {
      throw log.unableToSerializeInAvro( e );
    }
    return out.toByteArray();
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

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write( AvroSerializationProvider.getMajorVersion() );
    out.write( AvroSerializationProvider.getMinorVersion() );
    Schema msgSchema = protocol.getType( "Message" );
    GenericDatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>( msgSchema );
    BinaryEncoder encoder = EncoderFactory.get().directBinaryEncoder( out, null );
    GenericRecord message = new GenericData.Record( msgSchema );
    message.put( "classReferences", classReferences );
    message.put( "operations", operations );
    operations = null;
    try {
      writer.write( message, encoder );
      encoder.flush();
    }
    catch ( IOException e ) {
      throw log.unableToSerializeInAvro(e);
    }
    return out.toByteArray();
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.