public final class GlobFilter extends Object implements FilenameFilter
java.io.FilenameFilter
which accepts file
names matching a given glob pattern (as used by Unix shells).
This class is not thread-safe.
Caveat: on Windows, '\' (backslash) is always considered to be the path separator (e.g. C:\foo\bar*\*.xml) and thus, cannot be used to escape special characters in the pattern passed to the constructor and to the convenience functions.
Modifier and Type | Field and Description |
---|---|
GlobMatcher |
globMatcher
The underlying matcher.
|
String |
globPattern
The string representation of the glob pattern.
|
Constructor and Description |
---|
GlobFilter(String globPattern)
Constructs filter using specified glob pattern.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(File dir,
String name) |
static GlobFilter |
create(String globPattern)
Convenience method: creates a filter for specified pattern, but unlike
the constructor, this method does not raise an exception if this fails.
|
static File[] |
glob(File patternsFile)
Utility used by the
glob(String) convenience method: List all
the files matching specified glob pattern. |
static File[] |
glob(String patterns)
Convenience method: List all the files matching specified glob pattern.
|
static File |
resolve(String path,
File baseDir,
boolean substituteTilde)
Utility used by the
glob(String) convenience method: Resolve
specified path against specified base directory. |
public final String globPattern
public final GlobMatcher globMatcher
public GlobFilter(String globPattern) throws PatternSyntaxException
globPattern
- the glob patternPatternSyntaxException
- if specified glob pattern cannot be
compiled into a java.util.regex.Pattern
public boolean accept(File dir, String name)
accept
in interface FilenameFilter
public static GlobFilter create(String globPattern)
null
.public static File[] glob(String patterns)
patterns
- a path, relative or absolute, possibly containing one
or more glob patterns. Example: "~/src/_?/[A-Z]*.java". If this
path is not absolute, it is resolved against the home directory of the
user if it starts with '~' and against the current working
directory otherwise.public static File resolve(String path, File baseDir, boolean substituteTilde)
glob(String)
convenience method: Resolve
specified path against specified base directory.path
- path to be made absolutebaseDir
- an absolute directory. Resolve path against this base
directory. May be null
which means: use the current
working directory.substituteTilde
- if true
and path starts with
'~', resolve path against the home directory of the userpublic static File[] glob(File patternsFile)
glob(String)
convenience method: List all
the files matching specified glob pattern.patternsFile
- an absolute, canonical file, whose path possibly
contains one or more glob patterns.
Example: "/home/john/src/_?/[A-Z]*.java".