本文整理汇总了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();
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}