4 import java.util.zip.*;
8 * A ClassPathEntry representing a ZIP or JAR file.
10 * Copyright (C) 2001, 2002 Eric D. Friedman (eric@hfriedman.rdsl.lmi.net)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * Created: Tuesday Aug 14 19:46:52 2001
28 * @author Eric D. Friedman
29 * @version $Id: ClassPathZip.java,v 1.2 2002/11/30 04:36:06 paulk Exp $
32 class ClassPathZip extends ClassPathEntry {
33 private File zipOrJar;
36 * Creates a ClassPathZip instance representing <code>zipOrJar</code>
38 * @param zipOrJar a <code>File</code> value
39 * @return a <code>ClassPathZip</code> value
40 * @exception IOException if an error occurs
42 ClassPathZip (File zipOrJar) {
44 this.zipOrJar = zipOrJar;
48 * Load all of the classes in the zip/jar and set the loaded flag
51 * @exception IOException if an error occurs
53 void load() throws IOException {
54 ZipFile zipFile = new ZipFile(zipOrJar);
55 Enumeration enum = zipFile.entries();
56 while (enum.hasMoreElements()) {
57 ZipEntry zipEntry = (ZipEntry)enum.nextElement();
58 String current = zipEntry.getName();
59 if (current.toLowerCase().endsWith(".class")) {
60 current = current.substring(0, current.length() - 6);
61 current = current.replace('/', '.');
62 current = current.replace('\\', '.');
63 current = current.replace('$', '.');
64 super.addClass(current);
71 * Return the zip/jar name as our string.
73 * @return a <code>String</code> value
75 public String toString() {
76 return zipOrJar.toString();
81 * $Log: ClassPathZip.java,v $
82 * Revision 1.2 2002/11/30 04:36:06 paulk
83 * load() method now replaces a $ with a period (.) in class names. Thanks to Petter Mahlen.
87 // End of ClassPathZip.java