KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > util > Archive


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.util;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.Set JavaDoc;
25
26 /**
27  * Utility methods for working with zip/jar archives.
28  *
29  * @author David Hovemeyer
30  */

31 public class Archive {
32
33     /**
34      * File extensions that indicate an archive (zip, jar, or similar).
35      */

36     static public final Set JavaDoc<String JavaDoc> ARCHIVE_EXTENSION_SET = new HashSet JavaDoc<String JavaDoc>();
37     static {
38         ARCHIVE_EXTENSION_SET.add(".jar");
39         ARCHIVE_EXTENSION_SET.add(".zip");
40         ARCHIVE_EXTENSION_SET.add(".war");
41         ARCHIVE_EXTENSION_SET.add(".ear");
42         ARCHIVE_EXTENSION_SET.add(".sar");
43     }
44
45     /**
46      * Determine whether or not the given filename appears to
47      * identify a zip/jar archive.
48      *
49      * @param fileName the filename
50      * @return true if the filename appears to identify an archive,
51      * false otherwise
52      */

53     public static boolean isArchiveFileName(String JavaDoc fileName) {
54         int lastDot = fileName.lastIndexOf('.');
55         if (lastDot < 0) {
56             return false;
57         }
58         String JavaDoc extension = fileName.substring(lastDot).toLowerCase(Locale.ENGLISH);
59         return ARCHIVE_EXTENSION_SET.contains(extension);
60     }
61 }
62
Popular Tags