Source code: jsd/ftp/jar/JarSelectiveExtractor.java
1 /*
2 * ----------------------------------------------------------------------------
3 * JStrangeDownloader and all accompanying source code files are
4 * Copyright (C) 2002 Dusty Davidson (dustyd@iastate.edu)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * ----------------------------------------------------------------------------
20 *
21 * Please see gpl.txt for the full text of the GNU General Public
22 * License.
23 */
24
25 package jsd.ftp.jar;
26
27 import java.io.File;
28 import java.io.InputStream;
29 import java.io.OutputStream;
30 import java.io.FileOutputStream;
31 import java.util.Enumeration;
32 import java.util.zip.ZipFile;
33 import java.util.zip.ZipEntry;
34 import java.util.jar.JarFile;
35
36
37 /**
38 * This is JAR file extractor class. It extracts the JAR file
39 * in a separate thread. Where we are passing a MyJarObserver
40 * object to track the current status of this decompression.
41 *
42 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
43 */
44 public
45 class JarSelectiveExtractor extends JarExtractor {
46
47 private ZipEntry mEntry[];
48
49 public JarSelectiveExtractor(ZipEntry entry[], File jarFile, File dir) {
50 super(jarFile, dir);
51 mEntry = entry;
52 }
53
54 /**
55 * invoke a new thread and start decompression
56 */
57 public void extract() {
58 Thread th = new Thread(this);
59 th.start();
60 }
61
62 public void run() {
63
64 mbIsPauseRequest = false;
65 mbIsStopRequest = false;
66
67 mObserverCont.start();
68 try {
69 ZipFile jf = new JarFile(mJarFile);
70 mObserverCont.setCount(mEntry.length);
71
72 for(int i=0; i<mEntry.length; i++) {
73
74 // check request
75 while (mbIsPauseRequest && (!mbIsStopRequest) ) {
76 Thread.sleep(100);
77 }
78
79 if (mbIsStopRequest) {
80 return;
81 }
82 extract(jf, mEntry[i]);
83 mObserverCont.setNext(mEntry[i]);
84 }
85 } catch (Exception ex) {
86 mObserverCont.setError(ex.getMessage());
87 } finally {
88 mbIsStopRequest = true;
89 mObserverCont.end();
90 }
91 }
92
93 /**
94 * get jar file name
95 */
96 public String toString() {
97 return mJarFile.getAbsolutePath();
98 }
99
100 }