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


Java FileReader.close方法代码示例

本文整理汇总了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;
}
 
开发者ID:conversant,项目名称:mara,代码行数:22,代码来源:AvroUnitTestHelper.java

示例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()));
}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:24,代码来源:AvroToJsonConverter.java

示例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);
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:10,代码来源:AvroFileReader.java

示例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;
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:13,代码来源:AvroFileReader.java

示例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;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:32,代码来源:AvroUtil.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:14,代码来源:AvroUtilsTest.java

示例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();
        }
    }
}
 
开发者ID:mraad,项目名称:AvroToolbox,代码行数:36,代码来源:AvroToJson.java


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