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


Java JsonDecoder类代码示例

本文整理汇总了Java中org.apache.avro.io.JsonDecoder的典型用法代码示例。如果您正苦于以下问题:Java JsonDecoder类的具体用法?Java JsonDecoder怎么用?Java JsonDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: convertJsonToAvro

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
static void convertJsonToAvro(InputStream inputStream, OutputStream outputStream, Schema schema)
        throws IOException {
    DatumReader<Object> reader = new GenericDatumReader<>(schema);
    DatumWriter<Object> writer = new GenericDatumWriter<>(schema);

    Encoder binaryEncoder = EncoderFactory.get().binaryEncoder(outputStream, null);

    JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(schema, inputStream);
    Object datum = null;
    while (true) {
        try {
            datum = reader.read(datum, jsonDecoder);
        } catch (EOFException eofException) {
            break;
        }
        writer.write(datum, binaryEncoder);
        binaryEncoder.flush();
    }
    outputStream.flush();
}
 
开发者ID:rkluszczynski,项目名称:avro-cli,代码行数:21,代码来源:RawConverterUtil.java

示例2: readYarnClusterSubmissionFromCSFromInputStream

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
static YarnClusterSubmissionFromCS readYarnClusterSubmissionFromCSFromInputStream(
    final InputStream appInputStream, final InputStream jobInputStream) throws IOException {
  final JsonDecoder appDecoder = DecoderFactory.get().jsonDecoder(
      AvroYarnAppSubmissionParameters.getClassSchema(), appInputStream);
  final SpecificDatumReader<AvroYarnAppSubmissionParameters> appReader = new SpecificDatumReader<>(
      AvroYarnAppSubmissionParameters.class);
  final AvroYarnAppSubmissionParameters yarnClusterAppSubmissionParameters = appReader.read(null, appDecoder);

  final JsonDecoder jobDecoder = DecoderFactory.get().jsonDecoder(
      AvroYarnClusterJobSubmissionParameters.getClassSchema(), jobInputStream);
  final SpecificDatumReader<AvroYarnClusterJobSubmissionParameters> jobReader = new SpecificDatumReader<>(
      AvroYarnClusterJobSubmissionParameters.class);
  final AvroYarnClusterJobSubmissionParameters yarnClusterJobSubmissionParameters = jobReader.read(null, jobDecoder);

  return new YarnClusterSubmissionFromCS(yarnClusterAppSubmissionParameters, yarnClusterJobSubmissionParameters);
}
 
开发者ID:apache,项目名称:reef,代码行数:17,代码来源:YarnClusterSubmissionFromCS.java

示例3: generateFormDataFromJson

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
@Override
public RecordField generateFormDataFromJson(String avroSchema, String json)
        throws AvroUiSandboxServiceException {
    try {
        Schema schema = new Schema.Parser().parse(avroSchema);
        JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(schema, json);
        DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema);
        GenericRecord genericRecord = datumReader.read(null, jsonDecoder);
        return FormAvroConverter.createRecordFieldFromGenericRecord(genericRecord);
    } catch (Exception e) {
        throw Utils.handleException(e);
    }
}
 
开发者ID:kaaproject,项目名称:avro-ui,代码行数:14,代码来源:AvroUiSandboxServiceImpl.java

示例4: fromInputStream

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
/**
 * Reads avro object from input stream.
 *
 * @param inputStream The input stream to read from
 * @return Avro object
 * @throws IOException
 */
AvroYarnJobSubmissionParameters fromInputStream(final InputStream inputStream) throws IOException {
  final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(
          AvroYarnJobSubmissionParameters.getClassSchema(), inputStream);
  final SpecificDatumReader<AvroYarnJobSubmissionParameters> reader = new SpecificDatumReader<>(
          AvroYarnJobSubmissionParameters.class);
  return reader.read(null, decoder);
}
 
开发者ID:apache,项目名称:reef,代码行数:15,代码来源:AvroYarnJobSubmissionParametersSerializer.java

示例5: readYarnAppSubmissionParametersFromInputStream

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
static AvroYarnAppSubmissionParameters readYarnAppSubmissionParametersFromInputStream(
    final InputStream inputStream) throws IOException {
  final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(
      AvroYarnAppSubmissionParameters.getClassSchema(), inputStream);
  final SpecificDatumReader<AvroYarnAppSubmissionParameters> reader = new SpecificDatumReader<>(
      AvroYarnAppSubmissionParameters.class);
  return reader.read(null, decoder);
}
 
开发者ID:apache,项目名称:reef,代码行数:9,代码来源:YarnBootstrapDriverConfigGenerator.java

示例6: readYarnJobSubmissionParametersFromInputStream

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
static AvroYarnJobSubmissionParameters readYarnJobSubmissionParametersFromInputStream(
    final InputStream inputStream) throws IOException {
  final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(
      AvroYarnJobSubmissionParameters.getClassSchema(), inputStream);
  final SpecificDatumReader<AvroYarnJobSubmissionParameters> reader = new SpecificDatumReader<>(
      AvroYarnJobSubmissionParameters.class);
  return reader.read(null, decoder);
}
 
开发者ID:apache,项目名称:reef,代码行数:9,代码来源:YarnBootstrapDriverConfigGenerator.java

示例7: fromInputStream

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
/**
 * Reads avro object from input stream.
 *
 * @param inputStream The input stream to read from
 * @return Avro object
 * @throws IOException
 */
AvroMultiRuntimeAppSubmissionParameters fromInputStream(final InputStream inputStream) throws IOException {
  final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(
          AvroMultiRuntimeAppSubmissionParameters.getClassSchema(), inputStream);
  final SpecificDatumReader<AvroMultiRuntimeAppSubmissionParameters> reader = new SpecificDatumReader<>(
          AvroMultiRuntimeAppSubmissionParameters.class);
  return reader.read(null, decoder);
}
 
开发者ID:apache,项目名称:reef,代码行数:15,代码来源:AvroMultiRuntimeAppSubmissionParametersSerializer.java

示例8: createDecoder

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected Decoder createDecoder() throws IOException {
  switch(codecType) {
    case BINARY:
      return new BinaryDecoder(getOrCreateInputStream());
    case JSON:
      return new JsonDecoder(schema, getOrCreateInputStream());
  }
  return null;
}
 
开发者ID:galaxyeye,项目名称:gora-0.3-simplified,代码行数:11,代码来源:AvroStore.java

示例9: getResultsSince

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
public <T extends SpecificRecordBase> List<T> getResultsSince(Endpoint ep, Class<T> cls,
		Schema schema, long since) {

	ArrayList<T> reslist = new ArrayList<T>();	

	DBCollection c  = db.getCollection(COLL_AVAIL);
	DBCursor curs = null;
	try{
	if(ep==null){
		curs = c.find();
	}else{

		DBObject q =
				QueryBuilder.start().and(
						QueryBuilder.start(RESULT_KEY).is(ep.getUri().toString()).get(),
						QueryBuilder.start("endpointResult.start").greaterThan(since).get()).get();
		log.info("[EXEC] {}",q);
		curs = c.find(q);
	}

	while(curs.hasNext()){
		DBObject o = curs.next();
		SpecificDatumReader r = new SpecificDatumReader<T>(cls);
		JsonDecoder d;
		try {
			d = DecoderFactory.get().jsonDecoder(schema, o.toString());
			T t =(T) r.read(null, d);
			reslist.add(t);
		} catch (IOException e) {
			log.error("GET RESULT Exception: {} {}", ep.getUri(), ExceptionHandler.logAndtoString(e,true));
		}
	}
	}finally{
		if(curs!=null)
			curs.close();
	}
	return reslist;

}
 
开发者ID:pyvandenbussche,项目名称:sparqles,代码行数:40,代码来源:MongoDBManager.java

示例10: scan

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
private <T> List<T> scan(Endpoint ep,String colName, Class<T> cls, Schema schema, String key) {
	ArrayList<T> reslist = new ArrayList<T>();	

	
	DBCollection c  = db.getCollection(colName);
	DBCursor curs = null;
	try{
		if(ep==null){
			curs = c.find().batchSize(50).addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);
		}else{
			BasicDBObject q = new BasicDBObject();
			q.append(key, ep.getUri().toString());
			curs = c.find(q).batchSize(50).addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT);
		}

		while(curs.hasNext()){
			DBObject o = curs.next();
			SpecificDatumReader r = new SpecificDatumReader<T>(cls);
			JsonDecoder d;
			try {
				d = DecoderFactory.get().jsonDecoder(schema, o.toString());
				T t =(T) r.read(null, d);
				reslist.add(t);
			} catch (IOException e) {
				log.error("SCAN Exception: {}:{}:{} {}", ep.getUri(),colName, cls, ExceptionHandler.logAndtoString(e,true));
			}
		}
	}finally{
		if(curs!=null)
			curs.close();
	}

	return reslist;
}
 
开发者ID:pyvandenbussche,项目名称:sparqles,代码行数:35,代码来源:MongoDBManager.java

示例11: EventReader

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
/**
 * Create a new Event Reader
 * @param in
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public EventReader(DataInputStream in) throws IOException {
  this.in = in;
  this.version = in.readLine();
  
  if (!EventWriter.VERSION.equals(version)) {
    throw new IOException("Incompatible event log version: "+version);
  }
  
  this.schema = Schema.parse(in.readLine());
  this.reader = new SpecificDatumReader(schema);
  this.decoder = new JsonDecoder(schema, in);
}
 
开发者ID:rekhajoshm,项目名称:mapreduce-fork,代码行数:19,代码来源:EventReader.java

示例12: createGenericRequestFromRecord

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
public static Object createGenericRequestFromRecord(Schema requestSchema, JsonNode record) throws IOException {
  JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(requestSchema, record.toString());
  return new GenericDatumReader<>(requestSchema, requestSchema).read(null, jsonDecoder);
}
 
开发者ID:tfeng,项目名称:toolbox,代码行数:5,代码来源:AvroHelper.java

示例13: createSpecificRequestFromRecord

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
public static <T> T createSpecificRequestFromRecord(Class<T> requestClass, JsonNode record) throws IOException {
  JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(getSchema(requestClass), record.toString());
  return new SpecificDatumReader<>(requestClass).read(null, jsonDecoder);
}
 
开发者ID:tfeng,项目名称:toolbox,代码行数:5,代码来源:AvroHelper.java

示例14: createGenericRequestFromRecord

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
public static Object createGenericRequestFromRecord(Schema requestSchema, JsonNode record)
    throws IOException {
  JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(requestSchema, record.toString());
  return new GenericDatumReader<>(requestSchema, requestSchema).read(null, jsonDecoder);
}
 
开发者ID:tfeng,项目名称:play-plugins,代码行数:6,代码来源:AvroHelper.java

示例15: createSpecificRequestFromRecord

import org.apache.avro.io.JsonDecoder; //导入依赖的package包/类
public static <T> T createSpecificRequestFromRecord(Class<T> requestClass, JsonNode record)
    throws IOException {
  JsonDecoder jsonDecoder =
      DecoderFactory.get().jsonDecoder(getSchema(requestClass), record.toString());
  return new SpecificDatumReader<>(requestClass).read(null, jsonDecoder);
}
 
开发者ID:tfeng,项目名称:play-plugins,代码行数:7,代码来源:AvroHelper.java


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