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


Java DecoderFactory.get方法代码示例

本文整理汇总了Java中org.apache.avro.io.DecoderFactory.get方法的典型用法代码示例。如果您正苦于以下问题:Java DecoderFactory.get方法的具体用法?Java DecoderFactory.get怎么用?Java DecoderFactory.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.avro.io.DecoderFactory的用法示例。


在下文中一共展示了DecoderFactory.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.apache.avro.io.DecoderFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void init(Properties props, String topicName) {
	super.init(props, topicName);
	
    try {
    	// init registry configured in properties
    	SchemaRegistry<Schema> registry = (SchemaRegistry<Schema>) Class.forName(
                           props.getProperty(KafkaAvroMessageEncoder.KAFKA_MESSAGE_CODER_SCHEMA_REGISTRY_CLASS)
                      ).newInstance();
           registry.init(props);
           
           // use Cached Registry
           this.registry = registry;// TODO new CachedSchemaRegistry<Schema>(registry);
           
           decoderFactory = DecoderFactory.get();
           
       } catch (Exception e) {
           throw new MessageDecoderException(e);
       }
}
 
开发者ID:Produban,项目名称:openbus,代码行数:22,代码来源:AvroMessageDecoder.java

示例2: testGetDataBinary

import org.apache.avro.io.DecoderFactory; //导入方法依赖的package包/类
@Test
public void testGetDataBinary() throws java.io.IOException {
    // given
    UiSpecsPropertiesDto propertiesDto = new UiSpecsPropertiesDto();
    propertiesDto.setProperties(getFileAsObjectNode("jdbc_data_set_properties_with_schema.json"));
    propertiesDto.setDependencies(singletonList(getJdbcDataStoreProperties()));

    String dataSetDefinitionName = "JDBCDataset";

    // when
    Response schemaResponse = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(APPLICATION_JSON_UTF8_VALUE) //
            .expect().statusCode(200).log().ifError() //
            .post(getVersionPrefix() + "/runtimes/schema");

    Schema schema = new Schema.Parser().parse(schemaResponse.asInputStream());

    Response response = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(RuntimesController.AVRO_BINARY_MIME_TYPE_OFFICIAL_INVALID) //
            .expect().statusCode(200).log().ifError() //
            .post(getVersionPrefix() + "/runtimes/data");

    // then
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
    DecoderFactory decoderFactory = DecoderFactory.get();
    Decoder decoder = decoderFactory.binaryDecoder(response.asInputStream(), null);
    assertRecordsEqualsToTestValues(reader, decoder);
}
 
开发者ID:Talend,项目名称:components,代码行数:29,代码来源:JdbcComponentTestIT.java

示例3: testGetData

import org.apache.avro.io.DecoderFactory; //导入方法依赖的package包/类
@Test
public void testGetData() throws java.io.IOException {
    // given
    UiSpecsPropertiesDto propertiesDto = new UiSpecsPropertiesDto();
    propertiesDto.setProperties(getFileAsObjectNode("jdbc_data_set_properties_with_schema.json"));
    propertiesDto.setDependencies(singletonList(getJdbcDataStoreProperties()));

    String dataSetDefinitionName = "JDBCDataset";

    Response schemaResponse = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(APPLICATION_JSON_UTF8_VALUE) //
            .expect().statusCode(200).log().ifError() //
            .post(getVersionPrefix() + "/runtimes/schema");

    Schema schema = new Schema.Parser().parse(schemaResponse.asInputStream());

    // when
    Response response = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
            .accept(RuntimesController.AVRO_JSON_MIME_TYPE_OFFICIAL_INVALID) //
            .expect().statusCode(200).log().ifError() //
            .post(getVersionPrefix() + "/runtimes/data");

    // then
    GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
    DecoderFactory decoderFactory = DecoderFactory.get();
    Decoder decoder = decoderFactory.jsonDecoder(schema, response.asInputStream());

    assertRecordsEqualsToTestValues(reader, decoder);
}
 
开发者ID:Talend,项目名称:components,代码行数:30,代码来源:JdbcComponentTestIT.java

示例4: init

import org.apache.avro.io.DecoderFactory; //导入方法依赖的package包/类
/**
 * To remove certain fields from the Avro schema or records of a topic/table, set property
 * {topic/table name}.remove.fields={comma-separated, fully qualified field names} in workUnit.
 */
@Override
public EnvelopeSchemaConverter init(WorkUnitState workUnit) {
  if (workUnit.contains(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY)) {
    String removeFieldsPropName = workUnit.getProp(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY) + AvroProjectionConverter.REMOVE_FIELDS;
    if (workUnit.contains(removeFieldsPropName)) {
      this.fieldRemover = Optional.of(new AvroSchemaFieldRemover(workUnit.getProp(removeFieldsPropName)));
    } else {
      this.fieldRemover = Optional.absent();
    }
  }
  String registryFactoryField = workUnit.contains(KafkaSchemaRegistryFactory.KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS) ?
      workUnit.getProp(KafkaSchemaRegistryFactory.KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS) : DEFAULT_KAFKA_SCHEMA_REGISTRY_FACTORY_CLASS;
  try {
    KafkaSchemaRegistryFactory registryFactory = ((Class<? extends KafkaSchemaRegistryFactory>) Class.forName(registryFactoryField)).newInstance();
    this.registry = registryFactory.create(workUnit.getProperties());
  } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
    return null;
  }
  this.decoderFactory = DecoderFactory.get();
  this.readers = CacheBuilder.newBuilder().build(new CacheLoader<Schema, GenericDatumReader<GenericRecord>>() {
    @Override
    public GenericDatumReader<GenericRecord> load(final Schema key) throws Exception {
      return new GenericDatumReader<>(key);
    }
  });
  return this;
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:32,代码来源:EnvelopeSchemaConverter.java

示例5: decodeRecord

import org.apache.avro.io.DecoderFactory; //导入方法依赖的package包/类
public static <T> T decodeRecord(Class<T> recordClass, byte[] data) throws IOException {
  DecoderFactory decoderFactory = DecoderFactory.get();
  BinaryDecoder binaryDecoder = decoderFactory.binaryDecoder(data, null);
  SpecificDatumReader<T> datumReader = new SpecificDatumReader<>(getSchema(recordClass));
  return datumReader.read(null, binaryDecoder);
}
 
开发者ID:tfeng,项目名称:toolbox,代码行数:7,代码来源:AvroHelper.java


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