public static List<File> recursiveListLocalDir(File dir) {
    File[] files = dir.listFiles();
    // File#listFiles can return null when the path is invalid
    if (files == null) {
      return Collections.emptyList();
    }
    List<File> result = new ArrayList<>(files.length);
    for (File f : files) {
      if (f.isDirectory()) {
        result.addAll(recursiveListLocalDir(f));
        continue;
      }
      result.add(f);
    }
    return result;
  }
@Test
  public void recursiveList() throws Exception {
    File tmpDirFile = Files.createTempDir();
    tmpDirFile.deleteOnExit();

    Set<File> allFiles = new HashSet<>();
    // Create 10 files at randomly deep level in the directory
    for (int i = 0; i < 10; i++) {
      createFileOrDir(tmpDirFile, i, new Random(), allFiles);
    }

    List<File> listedFiles = CommonUtils.recursiveListLocalDir(tmpDirFile);
    assertEquals(allFiles, new HashSet<>(listedFiles));
  }