01: package com.bostechcorp.cbesb.console.help;
02:
03: import java.io.BufferedReader;
04: import java.io.FileNotFoundException;
05: import java.io.IOException;
06: import java.io.InputStream;
07: import java.io.InputStreamReader;
08: import java.util.Enumeration;
09: import java.util.jar.JarEntry;
10: import java.util.jar.JarFile;
11:
12: public final class ParseJarFile {
13:
14: private String jarFileName;
15:
16: public ParseJarFile(String jarFileName) {
17: this .jarFileName = jarFileName;
18: }
19:
20: public String getResource(String name) {
21: String result = "";
22: JarFile zf = null;
23: try {
24: // extracts just sizes only.
25: zf = new JarFile(jarFileName);
26: Enumeration e = zf.entries();
27: while (e.hasMoreElements()) {
28: JarEntry ze = (JarEntry) e.nextElement();
29:
30: if (ze.isDirectory()) {
31: continue;
32: }
33: if (ze.getName().equals(name)) {
34: InputStream is = zf.getInputStream(ze);
35: BufferedReader buff = new BufferedReader(
36: new InputStreamReader(is));
37: String strread = "";
38: while ((strread = buff.readLine()) != null) {
39: result += strread;
40: }
41: buff.close();
42: is.close();
43: break;
44: }
45: }
46:
47: } catch (FileNotFoundException e) {
48: e.printStackTrace();
49: } catch (IOException e) {
50: e.printStackTrace();
51: } finally {
52: if (zf != null)
53: try {
54: zf.close();
55: } catch (IOException e) {
56: e.printStackTrace();
57: }
58: }
59: return result;
60:
61: }
62: }
|