本文整理汇总了Java中org.apache.avro.reflect.ReflectDatumReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectDatumReader.read方法的具体用法?Java ReflectDatumReader.read怎么用?Java ReflectDatumReader.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.reflect.ReflectDatumReader
的用法示例。
在下文中一共展示了ReflectDatumReader.read方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReflect
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
public static void testReflect(Object value, Type type, String schema)
throws Exception {
// check that schema matches expected
Schema s = ReflectData.get().getSchema(type);
assertEquals(Schema.parse(schema), s);
// check that value is serialized correctly
ReflectDatumWriter<Object> writer = new ReflectDatumWriter<Object>(s);
ByteArrayOutputStream out = new ByteArrayOutputStream();
writer.write(value, EncoderFactory.get().directBinaryEncoder(out, null));
ReflectDatumReader<Object> reader = new ReflectDatumReader<Object>(s);
Object after =
reader.read(null,
DecoderFactory.get().binaryDecoder(out.toByteArray(), null));
assertEquals(value, after);
}
示例2: toObject
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
public T toObject(byte[] bytes) {
T object = null;
ReflectDatumReader<T> reader = null;
try {
Decoder decoder = DecoderFactory.get().binaryDecoder(bytes, null);
reader = new ReflectDatumReader<T>(schema);
object = reader.read(null, decoder);
} catch(Exception e) {
throw new SerializationException("An exception has thrown in Avro reflect deserialization process", e);
}
return object;
}
示例3: deserialize
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
private Object deserialize(byte[] data, Class<?> clazz){
try{
ReflectDatumReader datumReader = new ReflectDatumReader<>(clazz);
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(data, null);
return datumReader.read(null, decoder);
}catch(IOException e){
return null;
}
}
示例4: deserializeWalletExtension
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
@Override
public void deserializeWalletExtension(Wallet containingWallet, byte[] data) throws Exception {
ReflectDatumReader<KeyShareWalletExtension> datumReader = new ReflectDatumReader<>(KeyShareWalletExtension.class);
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(data, null);
KeyShareWalletExtension result = datumReader.read(null, decoder);
this.privateKey = result.privateKey;
this.otherPublicKey = result.otherPublicKey;
this.pkpDesktop = result.pkpDesktop;
this.pkpPhone = result.pkpPhone;
this.desktopBCParameters = result.desktopBCParameters;
this.phoneBCParameters = result.phoneBCParameters;
}
示例5: testAvroReflect
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
@Test
public void testAvroReflect() throws IOException {
loadProperties("flume-log4jtest-avro-reflect.properties");
PropertyConfigurator.configure(props);
Logger logger = LogManager.getLogger(TestLog4jAppenderWithAvro.class);
String msg = "This is log message number " + String.valueOf(0);
AppEvent appEvent = new AppEvent();
appEvent.setMessage(msg);
logger.info(appEvent);
Transaction transaction = ch.getTransaction();
transaction.begin();
Event event = ch.take();
Assert.assertNotNull(event);
Schema schema = ReflectData.get().getSchema(appEvent.getClass());
ReflectDatumReader<AppEvent> reader = new ReflectDatumReader<AppEvent>(AppEvent.class);
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(event.getBody(), null);
AppEvent recordFromEvent = reader.read(null, decoder);
Assert.assertEquals(msg, recordFromEvent.getMessage());
Map<String, String> hdrs = event.getHeaders();
Assert.assertNull(hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
Assert.assertNull("Schema URL should not be set",
hdrs.get(Log4jAvroHeaders.AVRO_SCHEMA_URL.toString()));
Assert.assertEquals("Schema string should be set", schema.toString(),
hdrs.get(Log4jAvroHeaders.AVRO_SCHEMA_LITERAL.toString()));
transaction.commit();
transaction.close();
}
示例6: toObject
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
public T toObject(byte[] bytes) {
Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, null);
ReflectDatumReader<T> reader = null;
try {
reader = new ReflectDatumReader<T>(clazz);
return reader.read(null, decoder);
} catch(IOException e) {
throw new SerializationException(e);
}
}
示例7: readContentIndexSummary
import org.apache.avro.reflect.ReflectDatumReader; //导入方法依赖的package包/类
public static ContentIndexSummary readContentIndexSummary(InputStream in) throws Exception{
Schema schema = ReflectData.get().getSchema(ContentIndexSummary.class);
ReflectDatumReader<ContentIndexSummary> reader = new ReflectDatumReader<ContentIndexSummary>(schema);
ContentIndexSummary index = reader.read(null, DecoderFactory.get().binaryDecoder(in, null));
return index;
}