File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\util\FileVisitor.java.html

1 package hudson.util;
2
3 import java.io.File;
4 import java.io.FileFilter;
5 import java.io.IOException;
6 import java.io.Serializable;
7
8 /**
9 * Visits files in a directory recursively.
10 *
11 * @since 1.343
12 * @see DirScanner
13 */
14 public abstract class FileVisitor {
15 /**
16 * Called for each file and directory that matches the criteria implied by {@link DirScanner}
17 *
18 * @param f
19 * Either a file or a directory.
20 * @param relativePath
21 * The file/directory name in question
22 */
23 public abstract void visit(File f, String relativePath) throws IOException;
24
25 /**
26 * Some visitors can handle symlinks as symlinks. Those visitors should implement
27 * this method to provide a different handling for symlink.
28 * <p>
29 * This method is invoked by those {@link DirScanner}s that can handle symlinks as symlinks.
30 * (Not every {@link DirScanner}s are capable of doing that, as proper symlink handling requires
31 * letting visitors decide whether or not to descend into a symlink directory.)
32 */
33 public void visitSymlink(File link, String target, String relativePath) throws IOException {
34 visit(link,relativePath);
35 }
36
37 /**
38 * Some visitors can handle symlinks as symlinks. Those visitors should implement
39 * this method and return true to have callers invoke {@link #visitSymlink(File, String, String)}.
40 * Note that failures to detect or read symlinks on certain platforms
41 * can cause {@link #visit} to be called on a file which is actually a symlink.
42 */
43 public boolean understandsSymlink() {
44 return false;
45 }
46
47 /**
48 * Decorates a visitor by a given filter.
49 */
50 public final FileVisitor with(FileFilter f) {
51 if(f==null) return this;
52 return new FilterFileVisitor(f,this);
53 }
54
55 private static final class FilterFileVisitor extends FileVisitor implements Serializable {
56 private final FileFilter filter;
57 private final FileVisitor visitor;
58
59 private FilterFileVisitor(FileFilter filter, FileVisitor visitor) {
60 this.filter = filter!=null ? filter : PASS_THROUGH;
61 this.visitor = visitor;
62 }
63
64 public void visit(File f, String relativePath) throws IOException {
65 if(f.isDirectory() || filter.accept(f))
66 visitor.visit(f,relativePath);
67 }
68
69 private static final FileFilter PASS_THROUGH = new FileFilter() {
70 public boolean accept(File pathname) {
71 return true;
72 }
73 };
74
75 private static final long serialVersionUID = 1L;
76 }
77 }
78