net.groboclown.util.io.v1
Class ExtensionFilenameFilter

java.lang.Object
  |
  +--net.groboclown.util.io.v1.ExtensionFilenameFilter
All Implemented Interfaces:
FilenameFilter
Direct Known Subclasses:
ExtensionFileFilter

public class ExtensionFilenameFilter
extends Object
implements FilenameFilter

Allows files with the given extention(s) to be accepted. You can also specify whether directories are allowed or not. This filter is case insensitive or sensitive, depending on the settings.

The extension strings passed in are the end-of-name Strings, meaning that each file must match at least one given string at the end. So, if you want to match all "DOC" files, pass in ".doc" to match.

By default, directories are allowed, independent of their names. If directories are not allowed, then the directory names must match the extension list.


Field Summary
private  boolean allowDirs
           
private  boolean caseInsensitive
           
private  String[] extensions
           
 
Constructor Summary
ExtensionFilenameFilter()
          Default Constructor.
ExtensionFilenameFilter(boolean caseInsensitive)
           
ExtensionFilenameFilter(String extension)
          Specify a single "end string" to match.
ExtensionFilenameFilter(String[] exts)
           Slow, but it works.
ExtensionFilenameFilter(String[] exts, boolean caseInsensitive)
           
ExtensionFilenameFilter(String extension, boolean caseInsensitive)
           
 
Method Summary
 boolean accept(File pathname)
          Accepts all files.
 boolean accept(File dir, String name)
          Accepts all files.
 void addExtension(String ext)
          Adds the given extension to the internal list.
 boolean allowsDirectories()
           
 void allowsDirectories(boolean on)
           
 boolean isCaseInsensitive()
           
protected  boolean matches(String filename, File file)
          Tests if the given file matches the list of extensions.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

extensions

private String[] extensions

allowDirs

private boolean allowDirs

caseInsensitive

private boolean caseInsensitive
Constructor Detail

ExtensionFilenameFilter

public ExtensionFilenameFilter()
Default Constructor.

ExtensionFilenameFilter

public ExtensionFilenameFilter(String extension)
Specify a single "end string" to match.

ExtensionFilenameFilter

public ExtensionFilenameFilter(String[] exts)

Slow, but it works.


ExtensionFilenameFilter

public ExtensionFilenameFilter(boolean caseInsensitive)

ExtensionFilenameFilter

public ExtensionFilenameFilter(String extension,
                               boolean caseInsensitive)

ExtensionFilenameFilter

public ExtensionFilenameFilter(String[] exts,
                               boolean caseInsensitive)
Method Detail

addExtension

public void addExtension(String ext)
Adds the given extension to the internal list.

allowsDirectories

public boolean allowsDirectories()
Returns:
whether the filter allows directories to pass.

allowsDirectories

public void allowsDirectories(boolean on)
Parameters:
on - true if filter allows directories to pass.

isCaseInsensitive

public boolean isCaseInsensitive()
Returns:
if the extension is case insensitive.

accept

public boolean accept(File dir,
                      String name)
Accepts all files.
Specified by:
accept in interface FilenameFilter

accept

public boolean accept(File pathname)
Accepts all files.

matches

protected boolean matches(String filename,
                          File file)
Tests if the given file matches the list of extensions.
Parameters:
filename - the name of the file.
file - the File object version of the file.


Written under the LGPL