org.apache.hadoop.io.IOUtils.listDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.apache.hadoop.io.IOUtils.listDirectory()方法的一些代码示例,展示了IOUtils.listDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.listDirectory()方法的具体详情如下:
包路径:org.apache.hadoop.io.IOUtils
类名称:IOUtils
方法名:listDirectory

IOUtils.listDirectory介绍

[英]Return the complete list of files in a directory as strings.

This is better than File#listDir because it does not ignore IOExceptions.
[中]以字符串形式返回目录中文件的完整列表。
这比File#listDir好,因为它不会忽略IOException。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

/**
 * Get a listing of the given directory using
 * {@link IOUtils#listDirectory(File, FilenameFilter)}.
 *
 * @param volume target volume. null if unavailable.
 * @param dir Directory to list.
 * @param filter {@link FilenameFilter} to filter the directory entries.
 * @throws IOException
 */
public List<String> listDirectory(
  @Nullable FsVolumeSpi volume, File dir,
  FilenameFilter filter) throws IOException {
 final long begin = profilingEventHook.beforeMetadataOp(volume, LIST);
 try {
  faultInjectorEventHook.beforeMetadataOp(volume, LIST);
  List<String> children = IOUtils.listDirectory(dir, filter);
  profilingEventHook.afterMetadataOp(volume, LIST, begin);
  return children;
 } catch(Exception e) {
  onFailure(volume, begin);
  throw e;
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

/**
 * Get the next subdirectory within the block pool slice.
 *
 * @return         The next subdirectory within the block pool slice, or
 *                   null if there are no more.
 */
private String getNextSubDir(String prev, File dir)
   throws IOException {
 List<String> children =
   IOUtils.listDirectory(dir, SubdirFilter.INSTANCE);
 cache = null;
 cacheMs = 0;
 if (children.size() == 0) {
  LOG.trace("getNextSubDir({}, {}): no subdirectories found in {}",
    storageID, bpid, dir.getAbsolutePath());
  return null;
 }
 Collections.sort(children);
 String nextSubDir = nextSorted(children, prev);
 if (nextSubDir == null) {
  LOG.trace("getNextSubDir({}, {}): no more subdirectories found in {}",
    storageID, bpid, dir.getAbsolutePath());
 } else {
  LOG.trace("getNextSubDir({}, {}): picking next subdirectory {} " +
    "within {}", storageID, bpid, nextSubDir, dir.getAbsolutePath());
 }
 return nextSubDir;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

state.curFinalizedDir, state.curFinalizedSubDir).toFile();
List<String> entries =
  IOUtils.listDirectory(dir, BlockFileFilter.INSTANCE);
if (entries.size() == 0) {
 entries = null;

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

state.curFinalizedDir, state.curFinalizedSubDir).toFile();
List<String> entries =
  IOUtils.listDirectory(dir, BlockFileFilter.INSTANCE);
if (entries.size() == 0) {
 entries = null;

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Get the next subdirectory within the block pool slice.
 *
 * @return         The next subdirectory within the block pool slice, or
 *                   null if there are no more.
 */
private String getNextSubDir(String prev, File dir)
   throws IOException {
 List<String> children =
   IOUtils.listDirectory(dir, SubdirFilter.INSTANCE);
 cache = null;
 cacheMs = 0;
 if (children.size() == 0) {
  LOG.trace("getNextSubDir({}, {}): no subdirectories found in {}",
    storageID, bpid, dir.getAbsolutePath());
  return null;
 }
 Collections.sort(children);
 String nextSubDir = nextSorted(children, prev);
 if (nextSubDir == null) {
  LOG.trace("getNextSubDir({}, {}): no more subdirectories found in {}",
    storageID, bpid, dir.getAbsolutePath());
 } else {
  LOG.trace("getNextSubDir({}, {}): picking next subdirectory {} " +
    "within {}", storageID, bpid, nextSubDir, dir.getAbsolutePath());
 }
 return nextSubDir;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-hdfs

List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() {
 @Override
 public boolean accept(File dir, String name) {

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() {
 @Override
 public boolean accept(File dir, String name) {

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test
 public void testListDirectory() throws IOException {
  File dir = new File("testListDirectory");
  Files.createDirectory(dir.toPath());
  try {
   Set<String> entries = new HashSet<String>();
   entries.add("entry1");
   entries.add("entry2");
   entries.add("entry3");
   for (String entry : entries) {
    Files.createDirectory(new File(dir, entry).toPath());
   }
   List<String> list = IOUtils.listDirectory(dir,
     NoEntry3Filter.INSTANCE);
   for (String entry : list) {
    Assert.assertTrue(entries.remove(entry));
   }
   Assert.assertTrue(entries.contains("entry3"));
   list = IOUtils.listDirectory(dir, null);
   for (String entry : list) {
    entries.remove(entry);
   }
   Assert.assertTrue(entries.isEmpty());
  } finally {
   FileUtils.deleteDirectory(dir);
  }
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
 public void testListDirectory() throws IOException {
  File dir = new File("testListDirectory");
  Files.createDirectory(dir.toPath());
  try {
   Set<String> entries = new HashSet<String>();
   entries.add("entry1");
   entries.add("entry2");
   entries.add("entry3");
   for (String entry : entries) {
    Files.createDirectory(new File(dir, entry).toPath());
   }
   List<String> list = IOUtils.listDirectory(dir,
     NoEntry3Filter.INSTANCE);
   for (String entry : list) {
    Assert.assertTrue(entries.remove(entry));
   }
   Assert.assertTrue(entries.contains("entry3"));
   list = IOUtils.listDirectory(dir, null);
   for (String entry : list) {
    entries.remove(entry);
   }
   Assert.assertTrue(entries.isEmpty());
  } finally {
   FileUtils.deleteDirectory(dir);
  }
 }
}

相关文章