当前位置: 首页>>代码示例>>Java>>正文


Java ReflectDatumReader.read方法代码示例

本文整理汇总了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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:AvroTestUtil.java

示例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;

}
 
开发者ID:keedio,项目名称:flume-enrichment-interceptor-skeleton,代码行数:15,代码来源:AVROReflectiveSerializer.java

示例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;
    }
}
 
开发者ID:ChristopherMann,项目名称:2FactorWallet,代码行数:10,代码来源:KeyShareStore.java

示例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;
}
 
开发者ID:ChristopherMann,项目名称:2FactorWallet,代码行数:13,代码来源:KeyShareWalletExtension.java

示例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();

}
 
开发者ID:cloudera,项目名称:cdk,代码行数:38,代码来源:TestLog4jAppenderWithAvro.java

示例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);
    }
}
 
开发者ID:we7,项目名称:voldemort,代码行数:11,代码来源:AvroReflectiveSerializer.java

示例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;
	}
 
开发者ID:datancoffee,项目名称:sirocco,代码行数:11,代码来源:AvroSerializer.java


注:本文中的org.apache.avro.reflect.ReflectDatumReader.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。