com.aliasi.io
Class FileExtensionFilter

java.lang.Object
  extended by com.aliasi.io.FileExtensionFilter
All Implemented Interfaces:
FileFilter

public class FileExtensionFilter
extends Object
implements FileFilter

A file filter that accepts all base files with a suffix with a specified value or one of a set of specified values. The extensions are specified in the constructor, and the filter may be set to accept or reject directories. A file is tested by name against String.endsWith(String).

Converting to FilenameFilter

After constructing a file extension filter, the corresponding file name filter may be obtained using the method fileNameFilter(). This class would simply implement both interfaces if it weren't for the ambiguity that causes between File#listFiles(FilenameFilter) and File.listFiles(FileFilter).

Since:
LingPipe1.0
Version:
4.0.1
Author:
Bob Carpenter

Constructor Summary
FileExtensionFilter(boolean acceptDirectories, String... extensions)
          Create a file filter that accepts files with the specified extensions, optionally accepting directories.
FileExtensionFilter(String... extensions)
          Create a file filter that accepts files with the specified extensions and accepts all directories.
FileExtensionFilter(String extension)
          Create a file filter that accepts files with the specified extension and accepts all directories.
FileExtensionFilter(String[] extensions, boolean acceptDirectories)
          Deprecated. Use the variable-length argument version FileExtensionFilter(boolean,String[]) instead.
FileExtensionFilter(String extension, boolean acceptDirectories)
          Create a file filter that accepts files with the specified extension, optionally accepting directories.
 
Method Summary
 boolean accept(File pathName)
          Return true if the specified file has an an acceptable suffix as specified in the constructor.
protected  boolean accept(String fileName)
          Returns true if the specified file name has an acceptable suffix as specified in the constructor.
 FilenameFilter fileNameFilter()
          Return the file name filter corresponding to this extension filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileExtensionFilter

@Deprecated
public FileExtensionFilter(String[] extensions,
                                      boolean acceptDirectories)
Deprecated. Use the variable-length argument version FileExtensionFilter(boolean,String[]) instead.

Create a file filter that accepts files with the specified extensions, optionally accepting directories.

Parameters:
extensions - Suffixes of files to accept.
acceptDirectories - true if all directories should be accepted by this filter.

FileExtensionFilter

public FileExtensionFilter(boolean acceptDirectories,
                           String... extensions)
Create a file filter that accepts files with the specified extensions, optionally accepting directories.

Parameters:
extensions - Suffixes of files to accept.
acceptDirectories - true if all directories should be accepted by this filter.

FileExtensionFilter

public FileExtensionFilter(String extension,
                           boolean acceptDirectories)
Create a file filter that accepts files with the specified extension, optionally accepting directories.

Parameters:
extension - Suffix of files to accept.
acceptDirectories - true if all directories should be accepted by this filter.

FileExtensionFilter

public FileExtensionFilter(String extension)
Create a file filter that accepts files with the specified extension and accepts all directories.

Parameters:
extension - Suffix of files to accept.

FileExtensionFilter

public FileExtensionFilter(String... extensions)
Create a file filter that accepts files with the specified extensions and accepts all directories.

Parameters:
extensions - Suffixes of files to accept.
Method Detail

accept

protected final boolean accept(String fileName)
Returns true if the specified file name has an acceptable suffix as specified in the constructor.

Parameters:
fileName - Name of file to test for acceptance.
Returns:
true If file name is acceptable.

accept

public boolean accept(File pathName)
Return true if the specified file has an an acceptable suffix as specified in the constructor.

Specified by:
accept in interface FileFilter
Parameters:
pathName - File to test for acceptance.
Returns:
true If file's name is acceptable.

fileNameFilter

public FilenameFilter fileNameFilter()
Return the file name filter corresponding to this extension filter.

Returns:
The file name filter for this file extension filter.