当前位置: 首页>>代码示例>>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;未经允许,请勿转载。