001: /*
002: * ExtensionFileFilter.java - 0.9.0 01/07/2001 - 12:35:59
003: *
004: * Copyright (C) 2001,,2003 2002 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.util.io.v1;
028:
029: import java.io.IOException;
030: import java.io.File;
031: import java.io.FilenameFilter;
032: import java.io.FileFilter;
033:
034: /**
035: * Allows files with the given extention(s) to be accepted. You can also
036: * specify whether directories are allowed or not. This filter is
037: * case insensitive or sensitive, depending on the settings.
038: * <P>
039: * The extension strings passed in are the end-of-name Strings, meaning
040: * that each file must match at least one given string at the end. So,
041: * if you want to match all "DOC" files, pass in ".doc" to match.
042: * <P>
043: * By default, directories are allowed, independent of their names. If
044: * directories are not allowed, then the directory names must match the
045: * extension list.
046: *
047: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
048: * @since January 7, 2001
049: * @version $Date: 2003/02/10 22:52:45 $
050: */
051: public class ExtensionFileFilter extends ExtensionFilenameFilter
052: implements FileFilter {
053: //--------------------------------------------------------------
054: // Private fields
055:
056: //--------------------------------------------------------------
057: // Constructors
058:
059: /**
060: * Default Constructor.
061: */
062: public ExtensionFileFilter() {
063: super ();
064: }
065:
066: /**
067: * Specify a single "end string" to match.
068: */
069: public ExtensionFileFilter(String extension) {
070: super (extension);
071: }
072:
073: /**
074: * <P>
075: * Slow, but it works.
076: */
077: public ExtensionFileFilter(String exts[]) {
078: super (exts);
079: }
080:
081: /**
082: *
083: */
084: public ExtensionFileFilter(boolean caseInsensitive) {
085: super (caseInsensitive);
086: }
087:
088: /**
089: *
090: */
091: public ExtensionFileFilter(String extension, boolean caseInsensitive) {
092: super (extension, caseInsensitive);
093: }
094:
095: /**
096: *
097: */
098: public ExtensionFileFilter(String exts[], boolean caseInsensitive) {
099: super (exts, caseInsensitive);
100: }
101:
102: //--------------------------------------------------------------
103: // Public methods
104:
105: /**
106: * Accepts some files.
107: */
108: public boolean accept(File pathname) {
109: if (pathname == null) {
110: throw new IllegalArgumentException("no null args");
111: }
112: return matches(pathname.getName(), pathname);
113: }
114:
115: //--------------------------------------------------------------
116: // Protected methods
117:
118: }
|