Package org.apache.commons.vfs2.filter
Class PrefixFileFilter
- java.lang.Object
-
- org.apache.commons.vfs2.filter.PrefixFileFilter
-
- All Implemented Interfaces:
java.io.Serializable
,FileFilter
public class PrefixFileFilter extends java.lang.Object implements FileFilter, java.io.Serializable
Filters file names for a certain prefix.For example, to print all files and directories in the current directory whose name starts with a
.
:FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(new PrefixFileFilter("."))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }
- Since:
- 2.4
- See Also:
- "http://commons.apache.org/proper/commons-io/", Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private IOCase
caseSensitivity
Whether the comparison is case sensitive.private java.util.List<java.lang.String>
prefixes
The file name prefixes to search for.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description PrefixFileFilter(java.lang.String... prefixes)
Constructs a new Prefix file filter for any of an array of prefixes.PrefixFileFilter(java.util.List<java.lang.String> prefixes)
Constructs a new Prefix file filter for a list of prefixes.PrefixFileFilter(IOCase caseSensitivity, java.lang.String... prefixes)
Constructs a new Prefix file filter for any of an array of prefixes specifying case-sensitivity.PrefixFileFilter(IOCase caseSensitivity, java.util.List<java.lang.String> prefixes)
Constructs a new Prefix file filter for a list of prefixes specifying case-sensitivity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(FileSelectInfo fileSelectInfo)
Checks to see if the file name starts with the prefix.java.lang.String
toString()
Provide a String representation of this file filter.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
caseSensitivity
private final IOCase caseSensitivity
Whether the comparison is case sensitive.
-
prefixes
private final java.util.List<java.lang.String> prefixes
The file name prefixes to search for.
-
-
Constructor Detail
-
PrefixFileFilter
public PrefixFileFilter(java.util.List<java.lang.String> prefixes)
Constructs a new Prefix file filter for a list of prefixes.- Parameters:
prefixes
- the prefixes to allow, must not be null
-
PrefixFileFilter
public PrefixFileFilter(IOCase caseSensitivity, java.util.List<java.lang.String> prefixes)
Constructs a new Prefix file filter for a list of prefixes specifying case-sensitivity.- Parameters:
caseSensitivity
- how to handle case sensitivity, null means case-sensitiveprefixes
- the prefixes to allow, must not be null
-
PrefixFileFilter
public PrefixFileFilter(java.lang.String... prefixes)
Constructs a new Prefix file filter for any of an array of prefixes.The array is not cloned, so could be changed after constructing the instance. This would be inadvisable however.
- Parameters:
prefixes
- the prefixes to allow, must not be null
-
PrefixFileFilter
public PrefixFileFilter(IOCase caseSensitivity, java.lang.String... prefixes)
Constructs a new Prefix file filter for any of an array of prefixes specifying case-sensitivity.- Parameters:
prefixes
- the prefixes to allow, must not be nullcaseSensitivity
- how to handle case sensitivity, null means case-sensitive
-
-
Method Detail
-
accept
public boolean accept(FileSelectInfo fileSelectInfo)
Checks to see if the file name starts with the prefix.- Specified by:
accept
in interfaceFileFilter
- Parameters:
fileSelectInfo
- the File to check- Returns:
- true if the file name starts with one of our prefixes
-
toString
public java.lang.String toString()
Provide a String representation of this file filter.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a String representation
-
-