KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > common > FileUtil


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * FileUtil.java
20  *
21  * This class is responsible for supplying simple file utilities
22  */

23
24 // package path
25
package com.rift.coad.lib.common;
26
27 // java imports
28
import com.rift.coad.lib.common.*;
29 import java.io.File JavaDoc;
30 import java.util.Vector JavaDoc;
31
32
33 /**
34  * This class is responsible for supplying simple file utilities
35  *
36  * @author Brett Chaldecott
37  */

38 public class FileUtil {
39     
40     /**
41      * A private constructor to prevent instanciation of this object.
42      */

43     private FileUtil() {
44     }
45     
46     /**
47      * This method filters the file list and returns a list of containing only
48      * jar files.
49      *
50      * @return The filtered list of files.
51      * @param files The unfiltered list of files.
52      * @param suffix The suffix to filter the file list on.
53      */

54     public static File JavaDoc[] filter(File JavaDoc[] files,String JavaDoc suffix) {
55         Vector JavaDoc filteredFiles = new Vector JavaDoc();
56         for (int index = 0; index < files.length; index++) {
57             File JavaDoc file = files[index];
58             if (file.isFile() != true) {
59                 continue;
60             }
61             String JavaDoc path = file.getPath();
62             if ((path.length() > 3) && (path.substring(path.length() -
63                     suffix.length()).equals(suffix))) {
64                filteredFiles.add(file);
65             }
66         }
67         File JavaDoc[] newFileList = new File JavaDoc[filteredFiles.size()];
68         return (File JavaDoc[])filteredFiles.toArray(newFileList);
69     }
70 }
71
Popular Tags