KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > io > v1 > ExtensionFileFilter


1 /*
2  * ExtensionFileFilter.java - 0.9.0 01/07/2001 - 12:35:59
3  *
4  * Copyright (C) 2001,,2003 2002 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26  
27  
28 package net.sourceforge.groboutils.util.io.v1;
29  
30 import java.io.IOException JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.FilenameFilter JavaDoc;
33 import java.io.FileFilter JavaDoc;
34
35
36
37 /**
38  * Allows files with the given extention(s) to be accepted. You can also
39  * specify whether directories are allowed or not. This filter is
40  * case insensitive or sensitive, depending on the settings.
41  * <P>
42  * The extension strings passed in are the end-of-name Strings, meaning
43  * that each file must match at least one given string at the end. So,
44  * if you want to match all "DOC" files, pass in ".doc" to match.
45  * <P>
46  * By default, directories are allowed, independent of their names. If
47  * directories are not allowed, then the directory names must match the
48  * extension list.
49  *
50  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
51  * @since January 7, 2001
52  * @version $Date: 2003/02/10 22:52:45 $
53  */

54 public class ExtensionFileFilter extends ExtensionFilenameFilter
55          implements FileFilter JavaDoc
56 {
57     //--------------------------------------------------------------
58
// Private fields
59

60     //--------------------------------------------------------------
61
// Constructors
62

63     /**
64      * Default Constructor.
65      */

66     public ExtensionFileFilter()
67     {
68         super();
69     }
70     
71     /**
72      * Specify a single "end string" to match.
73      */

74     public ExtensionFileFilter( String JavaDoc extension )
75     {
76         super( extension );
77     }
78     
79     /**
80      * <P>
81      * Slow, but it works.
82      */

83     public ExtensionFileFilter( String JavaDoc exts[] )
84     {
85         super( exts );
86     }
87     
88     
89     /**
90      *
91      */

92     public ExtensionFileFilter( boolean caseInsensitive )
93     {
94         super( caseInsensitive );
95     }
96      
97     
98     /**
99      *
100      */

101     public ExtensionFileFilter( String JavaDoc extension, boolean caseInsensitive )
102     {
103         super( extension, caseInsensitive );
104     }
105
106     
107     /**
108      *
109      */

110     public ExtensionFileFilter( String JavaDoc exts[], boolean caseInsensitive )
111     {
112         super( exts, caseInsensitive );
113     }
114
115     
116     //--------------------------------------------------------------
117
// Public methods
118

119     
120     /**
121      * Accepts some files.
122      */

123     public boolean accept( File JavaDoc pathname )
124     {
125         if (pathname == null)
126         {
127             throw new IllegalArgumentException JavaDoc( "no null args" );
128         }
129         return matches( pathname.getName(), pathname );
130     }
131     
132
133     
134     //--------------------------------------------------------------
135
// Protected methods
136

137     
138 }
139
Popular Tags