01: package com.kirkk.analyzer.framework.jar;
02:
03: import java.io.*;
04: import java.util.zip.*;
05: import java.util.*;
06:
07: public class JarFile {
08: private HashMap jarContents;
09: private Enumeration jarEntries;
10: private ZipFile zipFile;
11: private String 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()
24: && (classFileFound == false)) {
25: nextEntry = (ZipEntry) jarEntries.nextElement();
26: if ((nextEntry.getName().endsWith(".class"))) {
27: classFileFound = true;
28: }
29: }
30: if (classFileFound) {
31: this .nextClass = nextEntry.getName();
32: return true;
33: } else {
34: this .nextClass = null;
35: return false;
36: }
37: }
38:
39: public String nextClass() {
40: return this .nextClass;
41: }
42:
43: public String getFileName() {
44: return this .file.getAbsolutePath();
45: }
46:
47: public String getShortFileName() {
48: return this .file.getName();
49: }
50:
51: public void close() {
52: if (null != zipFile) {
53: try {
54: zipFile.close();
55: } catch (IOException exc) {
56: exc.printStackTrace();
57: }
58: }
59: }
60: }
|