@Test public void readEmptyDirectory() throws Exception { TemporaryFile tf = new TemporaryFile(true); Set<File> f = DirectoryReader.listAllRecursively(tf.getFile()); assertEquals(0, f.size()); tf.delete(); }
public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } private  DirectoryReader(); }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } private  DirectoryReader(); static Set<File> listAllRecursively(File directory); }
DirectoryReader { public static Set<File> listAllRecursively(File directory) { Ensure.not_null(directory, "directory == null"); Ensure.is_true(directory.isDirectory(), "file is not a directory"); Set<File> result = new HashSet<>(); File[] files = directory.listFiles(); for (File f : files) { if (f.isDirectory()) { result.addAll(listAllRecursively(f)); } else { result.add(f); } } return result; } private  DirectoryReader(); static Set<File> listAllRecursively(File directory);  }