Description: Preserves the Files.fileTreeTraverser() method that was removed from the public API in Guava 25. Author: Emmanuel Bourg Forwarded: not-needed --- a/guava/src/com/google/common/io/Files.java +++ b/guava/src/com/google/common/io/Files.java @@ -824,6 +824,48 @@ } /** + * Returns a {@link TreeTraverser} instance for {@link File} trees. + * + *

Warning: {@code File} provides no support for symbolic links, and as such there is no + * way to ensure that a symbolic link to a directory is not followed when traversing the tree. In + * this case, iterables created by this traverser could contain files that are outside of the + * given directory or even be infinite if there is a symbolic link loop. + * + * @since 15.0 + * @deprecated The returned {@link TreeTraverser} type is deprecated. Use the replacement method + * {@link #fileTraverser()} instead with the same semantics as this method. + */ + @Deprecated + public static com.google.common.collect.TreeTraverser fileTreeTraverser() { + return FILE_TREE_TRAVERSER; + } + + private static final com.google.common.collect.TreeTraverser FILE_TREE_TRAVERSER = + new com.google.common.collect.TreeTraverser() { + @Override + public Iterable children(File file) { + return fileTreeChildren(file); + } + + @Override + public String toString() { + return "Files.fileTreeTraverser()"; + } + }; + + private static Iterable fileTreeChildren(File file) { + // check isDirectory() just because it may be faster than listFiles() on a non-directory + if (file.isDirectory()) { + File[] files = file.listFiles(); + if (files != null) { + return Collections.unmodifiableList(Arrays.asList(files)); + } + } + + return Collections.emptyList(); + } + + /** * Returns the lexically cleaned form of the path name, usually (but not always) equivalent * to the original. The following heuristics are used: *