KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > kirkk > analyzer > framework > jar > JarFile


1 package com.kirkk.analyzer.framework.jar;
2
3 import java.io.*;
4 import java.util.zip.*;
5 import java.util.*;
6
7 public class JarFile {
8     private HashMap jarContents;
9     private Enumeration jarEntries;
10     private ZipFile zipFile;
11     private String JavaDoc nextClass;
12     private File file;
13
14     public JarFile(File file) throws ZipException, IOException {
15         this.file = file;
16         this.zipFile = new ZipFile(file);
17         this.jarEntries = zipFile.entries();
18     }
19
20     public boolean hasMoreClasses() {
21         boolean classFileFound = false;
22         ZipEntry nextEntry = null;
23         while (jarEntries.hasMoreElements() && (classFileFound == false) ) {
24             nextEntry = (ZipEntry) jarEntries.nextElement();
25             if ( (nextEntry.getName().endsWith(".class")) ) {
26                 classFileFound = true;
27             }
28         }
29         if (classFileFound) {
30             this.nextClass = nextEntry.getName();
31             return true;
32         } else {
33             this.nextClass = null;
34             return false;
35         }
36     }
37
38     public String JavaDoc nextClass() {
39         return this.nextClass;
40     }
41
42     public String JavaDoc getFileName() {
43         return this.file.getAbsolutePath();
44     }
45
46     public String JavaDoc getShortFileName() {
47         return this.file.getName();
48     }
49
50     public void close() {
51         if(null != zipFile) {
52             try {
53                 zipFile.close();
54             }
55             catch (IOException exc) {
56                 exc.printStackTrace();
57             }
58         }
59     }
60 }
Popular Tags