public class RegexFileFilter extends AbstractFileFilter implements java.io.Serializable
See java.util.regex.Pattern for regex matching rules.
e.g.
File dir = FileUtils.current();
FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
File[] files = dir.listFiles(fileFilter);
for (String file : files) {
System.out.println(file);
}
final Path dir = PathUtils.current();
final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$"));
//
// Walk one dir
Files.walkFileTree(dir, Collections.emptySet(), 1, visitor);
System.out.println(visitor.getPathCounters());
System.out.println(visitor.getFileList());
//
visitor.getPathCounters().reset();
//
// Walk dir tree
Files.walkFileTree(dir, visitor);
System.out.println(visitor.getPathCounters());
System.out.println(visitor.getDirList());
System.out.println(visitor.getFileList());
Serialization is deprecated and will be removed in 3.0.
| Modifier and Type | Field and Description |
|---|---|
private java.util.function.Function<java.nio.file.Path,java.lang.String> |
pathToString
How convert a path to a string.
|
private java.util.regex.Pattern |
pattern
The regular expression pattern that will be used to match file names.
|
private static long |
serialVersionUID |
EMPTY_STRING_ARRAY| Constructor and Description |
|---|
RegexFileFilter(java.util.regex.Pattern pattern)
Constructs a new regular expression filter for a compiled regular expression
|
RegexFileFilter(java.util.regex.Pattern pattern,
java.util.function.Function<java.nio.file.Path,java.lang.String> pathToString)
Constructs a new regular expression filter for a compiled regular expression
|
RegexFileFilter(java.lang.String pattern)
Constructs a new regular expression filter.
|
RegexFileFilter(java.lang.String pattern,
int flags)
Constructs a new regular expression filter with the specified flags.
|
RegexFileFilter(java.lang.String pattern,
IOCase ioCase)
Constructs a new regular expression filter with the specified flags case sensitivity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accept(java.io.File dir,
java.lang.String name)
Checks to see if the file name matches one of the regular expressions.
|
java.nio.file.FileVisitResult |
accept(java.nio.file.Path path,
java.nio.file.attribute.BasicFileAttributes attributes)
Checks to see if the file name matches one of the regular expressions.
|
private static java.util.regex.Pattern |
compile(java.lang.String pattern,
int flags)
Compiles the given pattern source.
|
private static int |
toFlags(IOCase ioCase)
Converts IOCase to Pattern compilation flags.
|
java.lang.String |
toString()
Returns a debug string.
|
accept, append, append, get, handle, postVisitDirectory, preVisitDirectory, toDefaultFileVisitResult, toFileVisitResult, visitFile, visitFileFailedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitand, matches, negate, orprivate static final long serialVersionUID
private final java.util.regex.Pattern pattern
private final transient java.util.function.Function<java.nio.file.Path,java.lang.String> pathToString
public RegexFileFilter(java.util.regex.Pattern pattern)
pattern - regular expression to match.java.lang.NullPointerException - if the pattern is null.public RegexFileFilter(java.util.regex.Pattern pattern,
java.util.function.Function<java.nio.file.Path,java.lang.String> pathToString)
pattern - regular expression to match.pathToString - How convert a path to a string.java.lang.NullPointerException - if the pattern is null.public RegexFileFilter(java.lang.String pattern)
pattern - regular string expression to matchjava.lang.NullPointerException - if the pattern is nullpublic RegexFileFilter(java.lang.String pattern,
int flags)
pattern - regular string expression to matchflags - pattern flags - e.g. Pattern.CASE_INSENSITIVEjava.lang.IllegalArgumentException - if the pattern is nullpublic RegexFileFilter(java.lang.String pattern,
IOCase ioCase)
pattern - regular string expression to matchioCase - how to handle case sensitivity, null means case-sensitivejava.lang.IllegalArgumentException - if the pattern is nullprivate static java.util.regex.Pattern compile(java.lang.String pattern,
int flags)
pattern - the source pattern.flags - the compilation flags.private static int toFlags(IOCase ioCase)
ioCase - case-sensitivity.public boolean accept(java.io.File dir,
java.lang.String name)
accept in interface java.io.FilenameFilteraccept in interface IOFileFilteraccept in class AbstractFileFilterdir - the file directory (ignored)name - the file namepublic java.nio.file.FileVisitResult accept(java.nio.file.Path path,
java.nio.file.attribute.BasicFileAttributes attributes)
accept in interface PathFilteraccept in interface IOFileFilterpath - the pathattributes - the path attributespublic java.lang.String toString()
toString in class AbstractFileFilter