本文整理汇总了Java中org.apache.avro.file.FileReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileReader.close方法的具体用法?Java FileReader.close怎么用?Java FileReader.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.file.FileReader
的用法示例。
在下文中一共展示了FileReader.close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchema
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
/**
*
* @param file
* @return
* @throws IOException
*/
public Schema getSchema(File file) throws IOException {
Schema schema = null;
FileReader<IndexedRecord> fileReader = null;
try {
DatumReader<IndexedRecord> reader = new GenericDatumReader<>();
fileReader = DataFileReader.openReader(file, reader);
schema = fileReader.getSchema();
}
finally {
if (fileReader != null) {
fileReader.close();
}
}
return schema;
}
示例2: convert
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
@Override
public FixFile convert(TestRun testRun, FixFile ff) throws IOException {
byte[] bytes = IOUtils.toByteArray(ff.getContent());
if (bytes.length == 0) {
return ff;
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
GenericDatumReader<Object> reader = new GenericDatumReader<>();
FileReader<Object> fileReader = DataFileReader.openReader(new SeekableByteArrayInput(bytes), reader);
try {
Schema schema = fileReader.getSchema();
DatumWriter<Object> writer = new GenericDatumWriter<>(schema);
JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, os);
for (Object datum : fileReader) {
writer.write(datum, encoder);
}
encoder.flush();
} finally {
fileReader.close();
}
return new FixFile(new ByteArrayInputStream(os.toByteArray()));
}
示例3: getSchema
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
@Override
public Schema getSchema(Configuration conf, Path path) throws IOException {
SeekableInput input = new FsInput(path, conf);
DatumReader<Object> reader = new GenericDatumReader<>();
FileReader<Object> fileReader = DataFileReader.openReader(input, reader);
org.apache.avro.Schema schema = fileReader.getSchema();
fileReader.close();
return avroData.toConnectSchema(schema);
}
示例4: readData
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
@Override
public Collection<Object> readData(Configuration conf, Path path) throws IOException {
ArrayList<Object> collection = new ArrayList<>();
SeekableInput input = new FsInput(path, conf);
DatumReader<Object> reader = new GenericDatumReader<>();
FileReader<Object> fileReader = DataFileReader.openReader(input, reader);
for (Object object: fileReader) {
collection.add(object);
}
fileReader.close();
return collection;
}
示例5: getAvroSchema
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
/**
* Get the schema of AVRO files stored in a directory
*/
public static Schema getAvroSchema(Path path, Configuration conf)
throws IOException {
FileSystem fs = path.getFileSystem(conf);
Path fileToTest;
if (fs.isDirectory(path)) {
FileStatus[] fileStatuses = fs.listStatus(path, new PathFilter() {
@Override
public boolean accept(Path p) {
String name = p.getName();
return !name.startsWith("_") && !name.startsWith(".");
}
});
if (fileStatuses.length == 0) {
return null;
}
fileToTest = fileStatuses[0].getPath();
} else {
fileToTest = path;
}
SeekableInput input = new FsInput(fileToTest, conf);
DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
FileReader<GenericRecord> fileReader = DataFileReader.openReader(input, reader);
Schema result = fileReader.getSchema();
fileReader.close();
return result;
}
示例6: getRecordFromFile
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
public static List<GenericRecord> getRecordFromFile(String path)
throws IOException {
Configuration config = new Configuration();
SeekableInput input = new FsInput(new Path(path), config);
DatumReader<GenericRecord> reader1 = new GenericDatumReader<>();
FileReader<GenericRecord> fileReader = DataFileReader.openReader(input, reader1);
List<GenericRecord> records = new ArrayList<>();
for (GenericRecord datum : fileReader) {
records.add(datum);
}
fileReader.close();
return records;
}
示例7: main
import org.apache.avro.file.FileReader; //导入方法依赖的package包/类
public final static void main(final String[] args) throws IOException, InterruptedException
{
if (args.length == 0)
{
System.err.format("Usage: %s scheme://host:port/path/to/file.avro [count]\n", AvroToJson.class.getSimpleName());
}
else
{
int count = args.length == 2 ? Integer.parseInt(args[1]) : -1;
final GenericDatumReader<Object> reader = new GenericDatumReader<Object>();
final Path path = new Path(args[0]);
final FsInput input = new FsInput(path, new Configuration());
final FileReader<Object> fileReader = DataFileReader.openReader(input, reader);
try
{
final Schema schema = fileReader.getSchema();
final DatumWriter<Object> writer = new GenericDatumWriter<Object>(schema);
final JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, System.out);
for (final Object datum : fileReader)
{
writer.write(datum, encoder);
if (--count == 0)
{
break;
}
}
encoder.flush();
System.out.println();
}
finally
{
fileReader.close();
}
}
}