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


Java EncoderFactory.get方法代碼示例

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


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

示例1: send

import org.apache.avro.io.EncoderFactory; //導入方法依賴的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.io.EncoderFactory; //導入方法依賴的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: serializeAvro

import org.apache.avro.io.EncoderFactory; //導入方法依賴的package包/類
protected  byte[] serializeAvro( GenericData.Record record,  Schema schema, String topic,  byte opType) throws IOException {
       short schemaId = getSchemaId(topic, schema);
    EncoderFactory encoderFactory = EncoderFactory.get();
    DatumWriter<GenericRecord> writer  = new GenericDatumWriter<GenericRecord>();
    writer.setSchema(schema);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(PROTO_MAGIC_V0);
    out.write(ByteBuffer.allocate(opTypeSize).put(opType).array() );
    out.write(ByteBuffer.allocate(idSize).putShort(schemaId).array());
    BinaryEncoder enc = encoderFactory.binaryEncoder(out, null);
    writer.write(record, enc);
    enc.flush();
    return out.toByteArray();
}
 
開發者ID:rogers,項目名稱:change-data-capture,代碼行數:15,代碼來源:GenericAvroMutationSerializer.java

示例4: encodeRecord

import org.apache.avro.io.EncoderFactory; //導入方法依賴的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

示例5: LiAvroSerializerBase

import org.apache.avro.io.EncoderFactory; //導入方法依賴的package包/類
public LiAvroSerializerBase()
{
  isKey = false;
  encoderFactory = EncoderFactory.get();
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:6,代碼來源:LiAvroSerializerBase.java

示例6: generateRecordsContainerEvent

import org.apache.avro.io.EncoderFactory; //導入方法依賴的package包/類
private Event generateRecordsContainerEvent(String appToken, LogSchema schema,
                                            List<LogEvent> logEvents, ProfileInfo clientProfile,
                                            ProfileInfo serverProfile, RecordHeader header) {
  if (clientProfile == null && includeClientProfile) {
    LOG.error("Can't  generate records container event. " + CLIENT_PROFILE_NOT_SET);
    throw new RuntimeException(CLIENT_PROFILE_NOT_SET);
  }

  if (serverProfile == null && includeServerProfile) {
    LOG.error("Can't  generate records container event. " + SERVER_PROFILE_NOT_SET);
    throw new RuntimeException(SERVER_PROFILE_NOT_SET);
  }

  Event event = null;
  RecordData logData = new RecordData();
  logData.setSchemaVersion(schema.getVersion());
  logData.setApplicationToken(appToken);
  logData.setRecordHeader(header);

  if (includeClientProfile) {
    if (clientProfile != null) {
      logData.setClientProfileBody(clientProfile.getBody());
      logData.setClientSchemaId(clientProfile.getSchemaId());
    }
  }

  if (includeServerProfile) {
    if (serverProfile != null) {
      logData.setServerProfileBody(serverProfile.getBody());
      logData.setServerSchemaId(serverProfile.getSchemaId());
    }
  }

  List<ByteBuffer> bytes = new ArrayList<>(logEvents.size());

  for (LogEvent logEvent : logEvents) {
    bytes.add(ByteBuffer.wrap(logEvent.getLogData()));
  }

  logData.setEventRecords(bytes);
  EncoderFactory factory = EncoderFactory.get();

  GenericDatumWriter<RecordData> writer = new GenericDatumWriter<>(logData.getSchema());
  LOG.debug("Convert load data [{}] to bytes.", logData);

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  factory.binaryEncoder(baos, null);
  BinaryEncoder encoder = factory.binaryEncoder(baos, null);
  try {
    writer.write(logData, encoder);
    encoder.flush();
    event = EventBuilder.withBody(baos.toByteArray());
  } catch (IOException ex) {
    LOG.warn("Can't convert avro object {} to binary. Exception catched: {}", logData, ex);
  }
  LOG.trace("Build flume event with array body [{}]", baos);
  return event;
}
 
開發者ID:kaaproject,項目名稱:kaa,代碼行數:59,代碼來源:FlumeAvroEventBuilder.java


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