當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。