1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
Description: Preserves the Files.fileTreeTraverser() method that was removed from the public API in Guava 25.
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/guava/src/com/google/common/io/Files.java
+++ b/guava/src/com/google/common/io/Files.java
@@ -830,6 +830,48 @@
}
/**
+ * Returns a {@link TreeTraverser} instance for {@link File} trees.
+ *
+ * <p><b>Warning:</b> {@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<File> fileTreeTraverser() {
+ return FILE_TREE_TRAVERSER;
+ }
+
+ private static final com.google.common.collect.TreeTraverser<File> FILE_TREE_TRAVERSER =
+ new com.google.common.collect.TreeTraverser<File>() {
+ @Override
+ public Iterable<File> children(File file) {
+ return fileTreeChildren(file);
+ }
+
+ @Override
+ public String toString() {
+ return "Files.fileTreeTraverser()";
+ }
+ };
+
+ private static Iterable<File> 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, <i>usually</i> (but not always) equivalent
* to the original. The following heuristics are used:
*
|