本文整理汇总了Java中org.apache.avro.Schema.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.parse方法的具体用法?Java Parser.parse怎么用?Java Parser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.Schema.Parser
的用法示例。
在下文中一共展示了Parser.parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MemberInfoDynDeser
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
/**
* 动态反序列:通过Schema文件进行动态反序列化操作
*
* @throws IOException
*/
public void MemberInfoDynDeser() throws IOException {
// 1.schema文件解析
Parser parser = new Parser();
Schema mSchema = parser.parse(this.getClass().getResourceAsStream("/Members.avsc"));
// 2.构建数据读对象
DatumReader<GenericRecord> mGr = new SpecificDatumReader<GenericRecord>(mSchema);
DataFileReader<GenericRecord> mDfr = new DataFileReader<GenericRecord>(new File("/Users/a/Desktop/tmp/members.avro"), mGr);
// 3.从序列化文件中进行数据反序列化取出数据
GenericRecord gr = null;
while (mDfr.hasNext()) {
gr = mDfr.next();
System.err.println("deser data:" + gr.toString());
}
mDfr.close();
System.out.println("Dyn Builder Ser Start Complete.");
}
示例2: MemberInfoDynSer
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
/**
* 动态序列化:通过动态解析Schema文件进行内容设置,并序列化内容
*
* @throws IOException
*/
public void MemberInfoDynSer() throws IOException {
// 1.解析schema文件内容
Parser parser = new Parser();
Schema mSchema = parser.parse(this.getClass().getResourceAsStream("/Members.avsc"));
// 2.构建数据写对象
DatumWriter<GenericRecord> mGr = new SpecificDatumWriter<GenericRecord>(mSchema);
DataFileWriter<GenericRecord> mDfw = new DataFileWriter<GenericRecord>(mGr);
// 3.创建序列化文件
mDfw.create(mSchema, new File("/Users/a/Desktop/tmp/members.avro"));
// 4.添加序列化数据
for (int i = 0; i < 20; i++) {
GenericRecord gr = new GenericData.Record(mSchema);
int r = i * new Random().nextInt(50);
gr.put("userName", "light-" + r);
gr.put("userPwd", "2016-" + r);
gr.put("realName", "滔滔" + r + "号");
mDfw.append(gr);
}
// 5.关闭数据文件写对象
mDfw.close();
System.out.println("Dyn Builder Ser Start Complete.");
}
示例3: testGenerateAvro3
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
@Test
public void testGenerateAvro3() {
try {
Parser parser = new Schema.Parser();
Schema peopleSchema = parser.parse(new File(getTestResource("people.avsc").toURI()));
GenericDatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(peopleSchema);
DataFileWriter<GenericRecord> dfw = new DataFileWriter<GenericRecord>(datumWriter);
File tempfile = File.createTempFile("karma-people", "avro");
tempfile.deleteOnExit();
dfw.create(peopleSchema, new FileOutputStream(tempfile));
JSONArray array = new JSONArray(IOUtils.toString(new FileInputStream(new File(getTestResource("people.json").toURI()))));
for(int i = 0; i < array.length(); i++)
{
dfw.append(generatePersonRecord(peopleSchema, array.getJSONObject(i)));
}
dfw.flush();
dfw.close();
} catch (Exception e) {
logger.error("testGenerateAvro3 failed:", e);
fail("Execption: " + e.getMessage());
}
}
示例4: JsonReader
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
public JsonReader(String dataFilepath, String schemaFilepath) throws Exception{
this.filepath = dataFilepath;
Parser parser = new Schema.Parser();
Schema schema = parser.parse(new File(schemaFilepath));
this.datumReader = new SpecificDatumReader<Object>(schema);
this.decoder = DecoderFactory.get().jsonDecoder(schema,
new FileInputStream(new File(dataFilepath)));
}
示例5: BinaryReader
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
public BinaryReader(String dataFilepath, String schemaFilepath) throws Exception{
this.filepath = dataFilepath;
Parser parser = new Schema.Parser();
Schema schema = parser.parse(new File(schemaFilepath));
DatumReader<Object> datumReader = new SpecificDatumReader<Object>(schema);
this.dataFileReader = new DataFileReader<>(new File(dataFilepath), datumReader);
}
示例6: FileWriter
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
public FileWriter(String schemaFile, String outputFile) throws IOException{
Parser parser = new Schema.Parser();
Schema schema = parser.parse(new File(schemaFile));
DatumWriter<Object> datumWriter = new SpecificDatumWriter<Object>(schema);
fileWriter = new DataFileWriter<>(datumWriter);
fileWriter.create(schema, new File(outputFile));
}
示例7: JsonFileWriter
import org.apache.avro.Schema.Parser; //导入方法依赖的package包/类
public JsonFileWriter(String schemaFile, String outputFilePath) throws Exception{
File outputFile = new File(outputFilePath);
if(outputFile == null || outputFile.getParentFile() == null || !outputFile.getParentFile().exists()){
throw new Exception("Invalid file path: " + outputFilePath);
}
Parser parser = new Schema.Parser();
Schema schema = parser.parse(new File(schemaFile));
datumWriter = new SpecificDatumWriter<Object>(schema);
OutputStream outputStream = new FileOutputStream(outputFile);
jsonEncoder = EncoderFactory.get().jsonEncoder(schema, outputStream);
}