本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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();
}
示例5: LiAvroSerializerBase
import org.apache.avro.io.EncoderFactory; //导入方法依赖的package包/类
public LiAvroSerializerBase()
{
isKey = false;
encoderFactory = EncoderFactory.get();
}
示例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;
}