DfsUtil { public static Set<Path> listFiles(FileSystem hdfs, Path path, boolean recurse, boolean filterMetaData) throws IOException { Set<Path> files = new HashSet<>(); try { RemoteIterator<LocatedFileStatus> filesIterator = hdfs.listFiles(path, recurse); while (filesIterator.hasNext()) { Path file = filesIterator.next().getPath(); if (!filterMetaData || !file.getName().startsWith(FILE_METADATA_PREFIX)) { files.add(file); } } } catch (FileNotFoundException exception) { } return files; }  static boolean canDoAction(FileSystem hdfs, String user, String[] groups, Path path, FsAction action); static Set<Path> listFiles(FileSystem hdfs, Path path, boolean recurse, boolean filterMetaData); static Set<Path> listDirs(FileSystem hdfs, Path path, boolean recurse, boolean filterMetaData);  }
@Test public void testListFiles() throws IllegalArgumentException, IOException { assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmq/t"), false, false).size()); assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmq/t"), false, false).size()); assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmq/t"), true, false).size()); assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmq/t"), true, true).size()); assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t"), false, false).size()); assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t"), false, false).size()); assertEquals(11, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t"), true, false).size()); assertEquals(8, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t"), true, true).size()); assertEquals(1, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t1"), false, false).size()); assertEquals(1, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t1"), true, false).size()); assertEquals(1, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t1"), true, true).size()); assertEquals(1, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t3"), false, false).size()); assertEquals(1, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t3"), true, false).size()); assertEquals(0, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t3"), true, true).size()); assertEquals(2, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t6"), false, false).size()); assertEquals(2, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t6"), true, false).size()); assertEquals(1, DfsUtil.listFiles(dfsServer.getFileSystem(), dfsServer.getPath("/tmp/t/t6"), true, true).size()); }