當前位置: 首頁>>代碼示例>>Java>>正文


Java SpecificDatumWriter.write方法代碼示例

本文整理匯總了Java中org.apache.avro.specific.SpecificDatumWriter.write方法的典型用法代碼示例。如果您正苦於以下問題:Java SpecificDatumWriter.write方法的具體用法?Java SpecificDatumWriter.write怎麽用?Java SpecificDatumWriter.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.avro.specific.SpecificDatumWriter的用法示例。


在下文中一共展示了SpecificDatumWriter.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public void send(COL_RDBMS event) throws Exception {
	EncoderFactory avroEncoderFactory = EncoderFactory.get();
	SpecificDatumWriter<COL_RDBMS> avroEventWriter = new SpecificDatumWriter<COL_RDBMS>(COL_RDBMS.SCHEMA$);
	
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	BinaryEncoder binaryEncoder = avroEncoderFactory.binaryEncoder(stream,null);

	try {
		avroEventWriter.write(event, binaryEncoder);
		binaryEncoder.flush();
	} catch (IOException e) {
		e.printStackTrace();
		throw e;
	}
	IOUtils.closeQuietly(stream);

	KeyedMessage<String, byte[]> data = new KeyedMessage<String, byte[]>(
			TOPIC, stream.toByteArray());

	producer.send(data);
}
 
開發者ID:iotoasis,項目名稱:SDA,代碼行數:22,代碼來源:AvroRdbmsDeviceInfoPublish.java

示例2: send

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public void send(COL_ONEM2M event) throws Exception {
	EncoderFactory avroEncoderFactory = EncoderFactory.get();
	SpecificDatumWriter<COL_ONEM2M> avroEventWriter = new SpecificDatumWriter<COL_ONEM2M>(COL_ONEM2M.SCHEMA$);
	
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	BinaryEncoder binaryEncoder = avroEncoderFactory.binaryEncoder(stream,null);

	try {
		avroEventWriter.write(event, binaryEncoder);
		binaryEncoder.flush();
	} catch (IOException e) {
		e.printStackTrace();
		throw e;
	}
	IOUtils.closeQuietly(stream);

	KeyedMessage<String, byte[]> data = new KeyedMessage<String, byte[]>(
			TOPIC, stream.toByteArray());

	producer.send(data);
}
 
開發者ID:iotoasis,項目名稱:SDA,代碼行數:22,代碼來源:AvroOneM2MDataPublish.java

示例3: serializeDatum

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public SerializedDatum serializeDatum(final TDomainClass domainObject) {

    try {
      final SpecificRecord record = avroRoundTripProjector.toAvro(domainObject);
      final Schema schema = record.getSchema();
      final SpecificDatumWriter bodyWriter = new SpecificDatumWriter(schema);

      final ByteArrayOutputStream bodyByteStream = new ByteArrayOutputStream();
      final BinaryEncoder binaryEncoder = EncoderFactory.get().directBinaryEncoder(bodyByteStream, null);

      bodyWriter.write(record, binaryEncoder);
      binaryEncoder.flush();
      bodyByteStream.flush();

      final ByteBuffer datumBody = ByteBuffer.wrap(bodyByteStream.toByteArray());

      bodyByteStream.close();

      final int datumSchemaVersion = datumSchemaRepository.getDatumTypeVersion(schema).getVersion();

      return new SerializedDatum(datumBody, new DatumTypeVersion(datumTypeId, datumSchemaVersion));

    } catch (final Exception e) {
      throw new RuntimeException("Could not create datum body", e);
    }
  }
 
開發者ID:outbrain,項目名稱:Aletheia,代碼行數:27,代碼來源:AvroDatumSerDe.java

示例4: serializeDatumEnvelope

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public ByteBuffer serializeDatumEnvelope(final DatumEnvelope envelope) {
  try {
    final SpecificDatumWriter<DatumEnvelope> envelopeWriter = new SpecificDatumWriter<>(envelope.getSchema());
    final ByteArrayOutputStream envelopeByteStream = new ByteArrayOutputStream();
    BinaryEncoder binaryEncoder = EncoderFactory.get().directBinaryEncoder(envelopeByteStream, null);
    binaryEncoder = EncoderFactory.get().directBinaryEncoder(envelopeByteStream, binaryEncoder);

    envelopeWriter.write(envelope, binaryEncoder);
    binaryEncoder.flush();
    envelopeByteStream.flush();

    return ByteBuffer.wrap(envelopeByteStream.toByteArray());
  } catch (final Exception e) {
    throw new RuntimeException("Could not serialize datum envelope", e);
  }
}
 
開發者ID:outbrain,項目名稱:Aletheia,代碼行數:17,代碼來源:AvroDatumEnvelopeSerDe.java

示例5: getInsertMessageBytes

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
private byte[] getInsertMessageBytes(InsertMessage insertMessage){

            byte[] result = null;

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
            SpecificDatumWriter writer = new SpecificDatumWriter<InsertMessage>(InsertMessage.getClassSchema());

            try {
                writer.write(insertMessage, encoder);
                encoder.flush();
                out.close();
                result = out.toByteArray();
            }catch (IOException e){
                return null;
            }

            return result;

        }
 
開發者ID:Stratio,項目名稱:Decision,代碼行數:21,代碼來源:HardwareEmulatorMain.java

示例6: getInsertMessageBytes

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
private byte[] getInsertMessageBytes(InsertMessage insertMessage){

        byte[] result = null;

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
        SpecificDatumWriter writer = new SpecificDatumWriter<InsertMessage>(InsertMessage.getClassSchema());

        try {
            writer.write(insertMessage, encoder);
            encoder.flush();
            out.close();
            result = out.toByteArray();
        }catch (IOException e){
            return null;
        }

        return result;

    }
 
開發者ID:Stratio,項目名稱:Decision,代碼行數:21,代碼來源:JavaToAvroSerializer.java

示例7: deserialize

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
private static <T> byte[] deserialize(
		final T avroObject,
		Schema avroSchema,
		Class<T> avroClass )
		throws IOException {

	ByteArrayOutputStream os = new ByteArrayOutputStream();
	BinaryEncoder encoder = ef.binaryEncoder(
			os,
			null);
	if (!writers.containsKey(avroClass.toString())) {
		writers.put(
				avroClass.toString(),
				new SpecificDatumWriter<T>(
						avroSchema));
	}

	SpecificDatumWriter<T> writer = writers.get(avroClass.toString());
	writer.write(
			avroObject,
			encoder);
	encoder.flush();
	return os.toByteArray();
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:25,代碼來源:TypeUtils.java

示例8: copy

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
/**
 * Performs a deep copy of a avro node message.  This does not reuse existing
 * decoders/encoders, so if you're going to do a lot of copying, use a NodeCopier.
 *
 * @param node The node to copy.
 * @return A copy of the node.
 */
public static Node copy(Node node) {
  try {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Encoder encoder = EncoderFactory.get().directBinaryEncoder(out, null);
    SpecificDatumWriter<Node> writer = new SpecificDatumWriter<Node>(Node.SCHEMA$);
    writer.write(node, encoder);

    SpecificDatumReader<Node> reader = new SpecificDatumReader<Node>(Node.SCHEMA$);
    Decoder decoder = DecoderFactory.get().binaryDecoder(
        new ByteArrayInputStream(out.toByteArray()), null);
    return reader.read(null, decoder);
  } catch (IOException e) {
    throw new RuntimeException("Unable to copy node.");
  }
}
 
開發者ID:kijiproject,項目名稱:kiji-mapreduce-lib,代碼行數:23,代碼來源:NodeUtils.java

示例9: getObject

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
private DBObject getObject(Object o, Schema s){
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	JsonEncoder e;
	try {
		e = EncoderFactory.get().jsonEncoder(s, baos);
		SpecificDatumWriter w = new SpecificDatumWriter(o.getClass());
		w.write(o, e);
		e.flush();
		DBObject dbObject = (DBObject)JSON.parse(baos.toString());
		return dbObject;

	} catch (IOException e1) {
		log.error("GET OBJECT Exception: {} {}", o.getClass(), ExceptionHandler.logAndtoString(e1,true));
	}
	return null;
}
 
開發者ID:pyvandenbussche,項目名稱:sparqles,代碼行數:17,代碼來源:MongoDBManager.java

示例10: serialize

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
/**
 * Serializes the field object using the datumWriter.
 */
public static<T extends SpecificRecord> void serialize(OutputStream os,
    SpecificDatumWriter<T> datumWriter, Schema schema, T object)
    throws IOException {

  BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(os, null);
  datumWriter.write(object, encoder);
  encoder.flush();
}
 
開發者ID:jianglibo,項目名稱:gora-boot,代碼行數:12,代碼來源:IOUtils.java

示例11: getAvroBytes

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public static byte[] getAvroBytes(Map<String, Object> data) {
    try {
        // Keep this independent from the code
        BulletAvro record = new BulletAvro(data);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        SpecificDatumWriter<BulletAvro> writer = new SpecificDatumWriter<>(BulletAvro.class);
        Encoder encoder = new EncoderFactory().directBinaryEncoder(stream, null);
        stream.reset();
        writer.write(record, encoder);
        encoder.flush();
        return stream.toByteArray();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
開發者ID:yahoo,項目名稱:bullet-record,代碼行數:16,代碼來源:BulletRecordTest.java

示例12: deserialize

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
private static <T> byte[] deserialize(final T avroObject, Schema avroSchema, Class<T> avroClass) throws IOException {

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        BinaryEncoder encoder = ef.binaryEncoder(os, null);
        if (!writers.containsKey(avroClass.toString())){
            writers.put(avroClass.toString(), new SpecificDatumWriter<T>(avroSchema));
        }

        SpecificDatumWriter<T> writer = writers.get(avroClass.toString());
        writer.write(avroObject, encoder);
        encoder.flush();
        return os.toByteArray();
    }
 
開發者ID:ngageoint,項目名稱:geowave-osm,代碼行數:14,代碼來源:TypeUtils.java

示例13: toBytes

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public byte[] toBytes(T object) {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    SpecificDatumWriter<T> datumWriter = null;
    try {
        Encoder encoder = EncoderFactory.get().binaryEncoder(output, null);
        datumWriter = new SpecificDatumWriter<T>(clazz);
        datumWriter.write(object, encoder);
        encoder.flush();
        output.close();
    } catch(Exception e) {
        throw new SerializationException("An exception has thrown in Avro specific serialization process", e);
    }
    return output.toByteArray();
}
 
開發者ID:keedio,項目名稱:flume-enrichment-interceptor-skeleton,代碼行數:15,代碼來源:AVROSpecificSerializer.java

示例14: transform

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
private byte[] transform(SNMPFloat snmp, String schemaName) throws Exception {
  Schema schema = new Schema.Parser().parse(new FileInputStream("schemas/"+schemaName+".avsc"));
  SpecificDatumWriter<SNMPFloat> writer = new SpecificDatumWriter<>(schema);
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  os.write(1);
  BinaryEncoder enc = EncoderFactory.get().binaryEncoder(os, null);
  writer.write(snmp, enc);
  enc.flush();
  byte[] data = os.toByteArray();
  return data;
}
 
開發者ID:mukatee,項目名稱:kafka-consumer,代碼行數:12,代碼來源:InFluxAvroTests.java

示例15: encodeRecord

import org.apache.avro.specific.SpecificDatumWriter; //導入方法依賴的package包/類
public static byte[] encodeRecord(IndexedRecord record) throws IOException {
  ByteArrayOutputStream stream = new ByteArrayOutputStream();
  try {
    EncoderFactory encoderFactory = EncoderFactory.get();
    BinaryEncoder binaryEncoder = encoderFactory.binaryEncoder(stream, null);
    SpecificDatumWriter<IndexedRecord> datumWriter = new SpecificDatumWriter<>(record.getSchema());
    datumWriter.write(record, binaryEncoder);
    binaryEncoder.flush();
  } finally {
    stream.close();
  }
  return stream.toByteArray();
}
 
開發者ID:tfeng,項目名稱:toolbox,代碼行數:14,代碼來源:AvroHelper.java


注:本文中的org.apache.avro.specific.SpecificDatumWriter.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。