net.sourceforge.groboutils.util.io.v1
Class ExtensionFilenameFilter

java.lang.Object
  extended bynet.sourceforge.groboutils.util.io.v1.ExtensionFilenameFilter
All Implemented Interfaces:
java.io.FilenameFilter
Direct Known Subclasses:
ExtensionFileFilter

public class ExtensionFilenameFilter
extends java.lang.Object
implements java.io.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. By default, the class is case-insensitive.

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.

Since:
January 7, 2001
Version:
$Date: 2003/02/10 22:52:45 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Constructor Summary
ExtensionFilenameFilter()
          Default Constructor.
ExtensionFilenameFilter(boolean caseInsensitive)
           
ExtensionFilenameFilter(java.lang.String extension)
          Specify a single "end string" to match.
ExtensionFilenameFilter(java.lang.String[] exts)
           Slow, but it works.
ExtensionFilenameFilter(java.lang.String[] exts, boolean caseInsensitive)
           
ExtensionFilenameFilter(java.lang.String extension, boolean caseInsensitive)
           
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Accepts some files.
 void addExtension(java.lang.String ext)
          Adds the given extension to the internal list.
 boolean allowsDirectories()
           
 void allowsDirectories(boolean on)
           
 boolean isCaseInsensitive()
           
protected  boolean matches(java.lang.String filename, java.io.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, toString, wait, wait, wait
 

Constructor Detail

ExtensionFilenameFilter

public ExtensionFilenameFilter()
Default Constructor.


ExtensionFilenameFilter

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


ExtensionFilenameFilter

public ExtensionFilenameFilter(java.lang.String[] exts)

Slow, but it works.


ExtensionFilenameFilter

public ExtensionFilenameFilter(boolean caseInsensitive)

ExtensionFilenameFilter

public ExtensionFilenameFilter(java.lang.String extension,
                               boolean caseInsensitive)

ExtensionFilenameFilter

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

addExtension

public void addExtension(java.lang.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(java.io.File dir,
                      java.lang.String name)
Accepts some files.

Specified by:
accept in interface java.io.FilenameFilter

matches

protected boolean matches(java.lang.String filename,
                          java.io.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.


Copyright © 2001-2003 by The GroboUtils Project