@Test public void listDirsShouldListDirsLocatedInPath() throws IOException { Path tempDir = Files.createTempDirectory(this.getClass().getSimpleName()); Path subDir1 = Files.createTempDirectory(tempDir, "list_me"); Path subDir2 = Files.createTempDirectory(tempDir, "list_me"); List<String> paths = HdfsUtils.listDirs(new Configuration(), tempDir.toString()); assertEquals(2, paths.size()); List<String> expecteds = Stream.of(subDir1.toString(), subDir2.toString()) .map(path -> String.format("file:%s", path)) .sorted().collect(Collectors.toList()); List<String> actuals = paths.stream().sorted().collect(Collectors.toList()); assertEquals(expecteds, actuals); }
public static List<String> listDirs(Configuration hadoopConf, String pathname) throws IOException { return Arrays .stream(FileSystem.get(hadoopConf).listStatus(new Path(pathname))) .filter(FileStatus::isDirectory) .map(x -> x.getPath().toString()) .collect(Collectors.toList()); }
HdfsUtils { public static List<String> listDirs(Configuration hadoopConf, String pathname) throws IOException { return Arrays .stream(FileSystem.get(hadoopConf).listStatus(new Path(pathname))) .filter(FileStatus::isDirectory) .map(x -> x.getPath().toString()) .collect(Collectors.toList()); } }
HdfsUtils { public static List<String> listDirs(Configuration hadoopConf, String pathname) throws IOException { return Arrays .stream(FileSystem.get(hadoopConf).listStatus(new Path(pathname))) .filter(FileStatus::isDirectory) .map(x -> x.getPath().toString()) .collect(Collectors.toList()); } private  HdfsUtils(); }
HdfsUtils { public static List<String> listDirs(Configuration hadoopConf, String pathname) throws IOException { return Arrays .stream(FileSystem.get(hadoopConf).listStatus(new Path(pathname))) .filter(FileStatus::isDirectory) .map(x -> x.getPath().toString()) .collect(Collectors.toList()); } private  HdfsUtils(); static void remove(Configuration hadoopConf, String pathname); static List<String> listDirs(Configuration hadoopConf, String pathname); static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter); }
HdfsUtils { public static List<String> listDirs(Configuration hadoopConf, String pathname) throws IOException { return Arrays .stream(FileSystem.get(hadoopConf).listStatus(new Path(pathname))) .filter(FileStatus::isDirectory) .map(x -> x.getPath().toString()) .collect(Collectors.toList()); } private  HdfsUtils(); static void remove(Configuration hadoopConf, String pathname); static List<String> listDirs(Configuration hadoopConf, String pathname); static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter);  }