IOUtils { public static List<String> listDirectory(File dir, FilenameFilter filter) throws IOException { ArrayList<String> list = new ArrayList<String> (); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath())) { for (Path entry: stream) { String fileName = entry.getFileName().toString(); if ((filter == null) || filter.accept(dir, fileName)) { list.add(fileName); } } } catch (DirectoryIteratorException e) { throw e.getCause(); } return list; }  static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close); static void copyBytes(InputStream in, OutputStream out, int buffSize); static void copyBytes(InputStream in, OutputStream out, Configuration conf); static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close); static void copyBytes(InputStream in, OutputStream out, long count,
      boolean close); static int wrappedReadForCompressedData(InputStream is, byte[] buf,
      int off, int len); static void readFully(InputStream in, byte buf[],
      int off, int len); static void skipFully(InputStream in, long len); static void cleanup(Log log, java.io.Closeable... closeables); static void closeStream(java.io.Closeable stream); static void closeSocket(Socket sock); static void writeFully(WritableByteChannel bc, ByteBuffer buf); static void writeFully(FileChannel fc, ByteBuffer buf,
      long offset); static List<String> listDirectory(File dir, FilenameFilter filter);  }
@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); } }