Package org.apache.commons.vfs2
Class PatternFileSelector
- java.lang.Object
-
- org.apache.commons.vfs2.PatternFileSelector
-
- All Implemented Interfaces:
FileSelector
public class PatternFileSelector extends java.lang.Object implements FileSelector
AFileSelector
that selects based on regular expressions.The regular expression specified in one of the constructors is matched against
FileName.getPath()
of all candidate files. If you want to match only against the base file name, make sure to prefix the pattern with".*\\/"
.- Since:
- 2.1
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Pattern
pattern
The extensions to select.
-
Constructor Summary
Constructors Constructor Description PatternFileSelector(java.lang.String regex)
Creates a new selector for the given pattern.PatternFileSelector(java.lang.String regex, int flags)
Creates a new selector for the given Pattern and flags.PatternFileSelector(java.util.regex.Pattern pattern)
Creates a new selector for the given pattern.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
includeFile(FileSelectInfo fileInfo)
Determines if a file or folder should be selected.java.lang.String
toString()
boolean
traverseDescendents(FileSelectInfo fileInfo)
Determines whether a folder should be traversed.
-
-
-
Constructor Detail
-
PatternFileSelector
public PatternFileSelector(java.util.regex.Pattern pattern)
Creates a new selector for the given pattern.See
PatternFileSelector
for a specification how the pattern is matched.- Parameters:
pattern
- The regular expressed used by this selector.
-
PatternFileSelector
public PatternFileSelector(java.lang.String regex)
Creates a new selector for the given pattern.See
PatternFileSelector
for a specification how the pattern is matched.- Parameters:
regex
- The regular expressed used by this selector.- See Also:
Pattern.compile(String, int)
-
PatternFileSelector
public PatternFileSelector(java.lang.String regex, int flags)
Creates a new selector for the given Pattern and flags.See
PatternFileSelector
for a specification how the pattern is matched.- Parameters:
regex
- The expression to be compiledflags
- Match flags, a bit mask.- See Also:
Pattern.compile(String, int)
-
-
Method Detail
-
includeFile
public boolean includeFile(FileSelectInfo fileInfo) throws java.lang.Exception
Determines if a file or folder should be selected.See
PatternFileSelector
for a specification how the pattern is matched.- Specified by:
includeFile
in interfaceFileSelector
- Parameters:
fileInfo
- The file selection information.- Returns:
- true if the file should be selected, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
traverseDescendents
public boolean traverseDescendents(FileSelectInfo fileInfo) throws java.lang.Exception
Determines whether a folder should be traversed.This implementation always returns true to make sure all leafs are inspected.
- Specified by:
traverseDescendents
in interfaceFileSelector
- Parameters:
fileInfo
- The file selection information.- Returns:
- true if descendants should be traversed, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
-