org.apache.hadoop.fs.FileUtil.list()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(159)

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

FileUtil.list介绍

[英]A wrapper for File#list(). This java.io API returns null when a dir is not a directory or for any I/O error. Instead of having null check everywhere File#list() is used, we will add utility API to get around this problem. For the majority of cases where we prefer an IOException to be thrown.
[中]文件#list()的包装器。这是java。当目录不是目录或任何I/O错误时,io API返回null。我们将添加实用程序API来解决这个问题,而不是在使用文件#list()时到处检查null。对于我们希望抛出IOException的大多数情况。

代码示例

代码示例来源:origin: apache/hbase

+ " file system configurations from xml files under directory " + replicationConfDir);
File confDir = new File(replicationConfDir, replicationClusterId);
String[] listofConfFiles = FileUtil.list(confDir);
for (String confFile : listofConfFiles) {
 if (new File(confDir, confFile).isFile() && confFile.endsWith(XML)) {

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

String[] names = FileUtil.list(localf);
results = new FileStatus[names.length];
int j = 0;

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

/**
 * Cleanup the detachDir.
 * 
 * If the directory is not empty report an error; Otherwise remove the
 * directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
 if (!DataNodeLayoutVersion.supports(
   LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion)
   && detachDir.exists() && detachDir.isDirectory()) {
  if (FileUtil.list(detachDir).length != 0) {
   throw new IOException("Detached directory " + detachDir
     + " is not empty. Please manually move each file under this "
     + "directory to the finalized directory if the finalized "
     + "directory tree does not have the file.");
  } else if (!detachDir.delete()) {
   throw new IOException("Cannot remove directory " + detachDir);
  }
 }
}

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

/**
 * Cleanup the detachDir. 
 * 
 * If the directory is not empty report an error; 
 * Otherwise remove the directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
 if (!DataNodeLayoutVersion.supports(
   LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion) &&
   detachDir.exists() && detachDir.isDirectory() ) {
  
   if (FileUtil.list(detachDir).length != 0 ) {
    throw new IOException("Detached directory " + detachDir +
      " is not empty. Please manually move each file under this " +
      "directory to the finalized directory if the finalized " +
      "directory tree does not have the file.");
   } else if (!detachDir.delete()) {
    throw new IOException("Cannot remove directory " + detachDir);
   }
 }
}

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

/**
 * Get a listing of the given directory using
 * {@link FileUtil#listFiles(File)}.
 *
 * @param volume  target volume. null if unavailable.
 * @param   dir directory to be listed.
 * @return  array of strings representing the directory entries.
 * @throws IOException
 */
public String[] list(
  @Nullable FsVolumeSpi volume, File dir) throws IOException {
 final long begin = profilingEventHook.beforeMetadataOp(volume, LIST);
 try {
  faultInjectorEventHook.beforeMetadataOp(volume, LIST);
  String[] children = FileUtil.list(dir);
  profilingEventHook.afterMetadataOp(volume, LIST, begin);
  return children;
 } catch(Exception e) {
  onFailure(volume, begin);
  throw e;
 }
}

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

/**
 * Cleanup the detachDir. 
 * 
 * If the directory is not empty report an error; 
 * Otherwise remove the directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
 if (!DataNodeLayoutVersion.supports(
   LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion) &&
   detachDir.exists() && detachDir.isDirectory() ) {
  
   if (FileUtil.list(detachDir).length != 0 ) {
    throw new IOException("Detached directory " + detachDir +
      " is not empty. Please manually move each file under this " +
      "directory to the finalized directory if the finalized " +
      "directory tree does not have the file.");
   } else if (!detachDir.delete()) {
    throw new IOException("Cannot remove directory " + detachDir);
   }
 }
}

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

/**
 * Cleanup the detachDir. 
 * 
 * If the directory is not empty report an error; 
 * Otherwise remove the directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
 if (!DataNodeLayoutVersion.supports(
   LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion) &&
   detachDir.exists() && detachDir.isDirectory() ) {
  
   if (FileUtil.list(detachDir).length != 0 ) {
    throw new IOException("Detached directory " + detachDir +
      " is not empty. Please manually move each file under this " +
      "directory to the finalized directory if the finalized " +
      "directory tree does not have the file.");
   } else if (!detachDir.delete()) {
    throw new IOException("Cannot remove directory " + detachDir);
   }
 }
}

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

/**
 * Cleanup the detachDir.
 * 
 * If the directory is not empty report an error; Otherwise remove the
 * directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
 if (!DataNodeLayoutVersion.supports(
   LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion)
   && detachDir.exists() && detachDir.isDirectory()) {
  if (FileUtil.list(detachDir).length != 0) {
   throw new IOException("Detached directory " + detachDir
     + " is not empty. Please manually move each file under this "
     + "directory to the finalized directory if the finalized "
     + "directory tree does not have the file.");
  } else if (!detachDir.delete()) {
   throw new IOException("Cannot remove directory " + detachDir);
  }
 }
}

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

boolean isBPDirEmpty(String bpid) throws IOException {
 File volumeCurrentDir = this.getCurrentDir();
 File bpDir = new File(volumeCurrentDir, bpid);
 File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT);
 File finalizedDir = new File(bpCurrentDir,
   DataStorage.STORAGE_DIR_FINALIZED);
 File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW);
 if (finalizedDir.exists() && !DatanodeUtil.dirNoFilesRecursive(
   finalizedDir)) {
  return false;
 }
 if (rbwDir.exists() && FileUtil.list(rbwDir).length != 0) {
  return false;
 }
 return true;
}

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

boolean isBPDirEmpty(String bpid) throws IOException {
 File volumeCurrentDir = this.getCurrentDir();
 File bpDir = new File(volumeCurrentDir, bpid);
 File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT);
 File finalizedDir = new File(bpCurrentDir,
   DataStorage.STORAGE_DIR_FINALIZED);
 File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW);
 if (finalizedDir.exists() && !DatanodeUtil.dirNoFilesRecursive(
   finalizedDir)) {
  return false;
 }
 if (rbwDir.exists() && FileUtil.list(rbwDir).length != 0) {
  return false;
 }
 return true;
}

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

/**
 * Cleanup the detachDir.
 * 
 * If the directory is not empty report an error; Otherwise remove the
 * directory.
 * 
 * @param detachDir detach directory
 * @throws IOException if the directory is not empty or it can not be removed
 */
private void cleanupDetachDir(File detachDir) throws IOException {
 if (!DataNodeLayoutVersion.supports(
   LayoutVersion.Feature.APPEND_RBW_DIR, layoutVersion)
   && detachDir.exists() && detachDir.isDirectory()) {
  if (FileUtil.list(detachDir).length != 0) {
   throw new IOException("Detached directory " + detachDir
     + " is not empty. Please manually move each file under this "
     + "directory to the finalized directory if the finalized "
     + "directory tree does not have the file.");
  } else if (!detachDir.delete()) {
   throw new IOException("Cannot remove directory " + detachDir);
  }
 }
}

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

@Test (timeout = 30000)
public void testListAPI() throws IOException {
 setupDirs();
 //Test existing files case 
 String[] files = FileUtil.list(partitioned);
 Assert.assertEquals("Unexpected number of pre-existing files", 2, files.length);
 //Test existing directory with no files case 
 File newDir = new File(tmp.getPath(),"test");
 newDir.mkdir();
 Assert.assertTrue("Failed to create test dir", newDir.exists());
 files = FileUtil.list(newDir);
 Assert.assertEquals("New directory unexpectedly contains files", 0, files.length);
 newDir.delete();
 Assert.assertFalse("Failed to delete test dir", newDir.exists());
 
 //Test non-existing directory case, this throws 
 //IOException
 try {
  files = FileUtil.list(newDir);
  Assert.fail("IOException expected on list() for non-existent dir "
    + newDir.toString());
 } catch(IOException ioe) {
  //Expected an IOException
 }
}

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

@Test (timeout = 30000)
public void testListAPI() throws IOException {
 setupDirs();
 //Test existing files case 
 String[] files = FileUtil.list(partitioned);
 Assert.assertEquals("Unexpected number of pre-existing files", 2, files.length);
 //Test existing directory with no files case 
 File newDir = new File(tmp.getPath(),"test");
 newDir.mkdir();
 Assert.assertTrue("Failed to create test dir", newDir.exists());
 files = FileUtil.list(newDir);
 Assert.assertEquals("New directory unexpectedly contains files", 0, files.length);
 newDir.delete();
 Assert.assertFalse("Failed to delete test dir", newDir.exists());
 
 //Test non-existing directory case, this throws 
 //IOException
 try {
  files = FileUtil.list(newDir);
  Assert.fail("IOException expected on list() for non-existent dir "
    + newDir.toString());
 } catch(IOException ioe) {
  //Expected an IOException
 }
}

相关文章