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) {
        Path fileName = entry.getFileName();
        if (fileName != null) {
          String fileNameStr = fileName.toString();
          if ((filter == null) || filter.accept(dir, fileNameStr)) {
            list.add(fileNameStr);
          }
        }
      }
    } catch (DirectoryIteratorException e) {
      throw e.getCause();
    }
    return list;
  }
@Test
  public void testListDirectory() throws IOException {
    File dir = new File("testListDirectory");
    Files.createDirectory(dir.toPath());
    try {
      Set<String> entries = new HashSet<>();
      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);
    }
  }