Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jsd/ftp/jar/JarAllExtractor.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 JarAllExtractor extends JarExtractor {
46  
47      public JarAllExtractor(File jarFile, File dir) {
48          super(jarFile, dir);
49      }
50      
51      /**
52       * invoke a new thread and start decompression
53       */
54      public void extract() {
55          Thread th = new Thread(this);
56          th.start();
57      }
58  
59      public void run() {
60  
61          mbIsPauseRequest = false;
62          mbIsStopRequest = false;
63  
64          mObserverCont.start();
65          try {
66              ZipFile jf = new JarFile(mJarFile);
67              mObserverCont.setCount(jf.size());
68              Enumeration en = jf.entries();
69  
70              while (en.hasMoreElements()) {
71  
72                  // check request
73                  while (mbIsPauseRequest && (!mbIsStopRequest) ) {
74                      Thread.sleep(100);
75                  }
76  
77                  if (mbIsStopRequest) {
78                      return;
79                  }
80  
81                  ZipEntry je = (ZipEntry)en.nextElement();
82                  extract(jf, je);
83                  mObserverCont.setNext(je);
84              }
85          } catch (Exception ex) {
86              mObserverCont.setError(ex.getMessage());
87          } finally {
88              mbIsStopRequest = true;
89              mObserverCont.end();
90          }
91      }
92  
93  }