home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / IAVAZIP.EXE / DATA.Z / processDelete.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-18  |  4.0 KB  |  160 lines

  1. package com.sfs.iavazip;
  2.  
  3. import com.sfs.awt.treeview.Folder;
  4. import com.sfs.awt.treeview.Item;
  5. import com.sfs.debug.Debug;
  6. import java.awt.Dialog;
  7. import java.awt.Window;
  8. import java.io.File;
  9. import java.io.FileOutputStream;
  10. import java.io.IOException;
  11. import java.io.InputStream;
  12. import java.util.Enumeration;
  13. import java.util.Vector;
  14. import java.util.zip.ZipEntry;
  15. import java.util.zip.ZipOutputStream;
  16.  
  17. class processDelete extends processDlg {
  18.    iavaZip mainApp;
  19.    ZipOutputStream tempZip;
  20.    // $FF: renamed from: is java.io.InputStream
  21.    InputStream field_0;
  22.    FileOutputStream fos;
  23.  
  24.    public processDelete(iavaZip var1) {
  25.       super(var1, "Delete entries ...");
  26.       this.mainApp = var1;
  27.       ((Dialog)this).setResizable(true);
  28.    }
  29.  
  30.    public void processCanceled() {
  31.       super.thread.stop();
  32.  
  33.       try {
  34.          if (this.field_0 != null) {
  35.             this.field_0.close();
  36.          }
  37.  
  38.          if (this.fos != null) {
  39.             this.fos.close();
  40.          }
  41.  
  42.          if (this.tempZip != null) {
  43.             this.tempZip.close();
  44.             File var1 = new File("temp.zip");
  45.             var1.delete();
  46.          }
  47.       } catch (IOException var2) {
  48.       }
  49.  
  50.       this.mainApp.setDefaultCursor();
  51.       this.mainApp.showStatus("Delete Files canceled.");
  52.    }
  53.  
  54.    public void run() {
  55.       this.mainApp.showStatus("Deleting files");
  56.       Vector var1 = new Vector();
  57.       ((processDlg)this).showStatus("building copy list ...");
  58.  
  59.       for(int var2 = 1; var2 < this.mainApp.tw.Root.Rows.size(); ++var2) {
  60.          Item var3 = (Item)this.mainApp.tw.Root.Rows.elementAt(var2);
  61.          if (!(var3 instanceof Folder) && !var3.isSelected()) {
  62.             var1.addElement(var3.getContent());
  63.             Debug.Info(((ZipEntry)var3.getContent()).getName());
  64.          }
  65.       }
  66.  
  67.       if (var1.size() > 0) {
  68.          try {
  69.             this.tempZip = new ZipOutputStream(new FileOutputStream("temp.zip"));
  70.          } catch (IOException var28) {
  71.             ((Throwable)var28).printStackTrace(System.out);
  72.          }
  73.  
  74.          super.pb.setMaximum((float)var1.size());
  75.          byte[] var4 = new byte[256];
  76.          ((processDlg)this).showHeading("Copying");
  77.          Enumeration var5 = var1.elements();
  78.  
  79.          try {
  80.             int var6 = 0;
  81.  
  82.             while(var5.hasMoreElements()) {
  83.                ZipEntry var31 = (ZipEntry)var5.nextElement();
  84.                ZipEntry var32 = new ZipEntry(var31.getName());
  85.                var32.setTime(var31.getTime());
  86.                this.tempZip.putNextEntry(var32);
  87.                this.field_0 = this.mainApp.zipFile.getInputStream(var31);
  88.                String var7 = var31.getName();
  89.                int var8;
  90.                if ((var8 = var7.lastIndexOf(var7)) != -1) {
  91.                   var7 = var7.substring(var8 + 1);
  92.                }
  93.  
  94.                ((processDlg)this).showStatus("copying " + var7);
  95.  
  96.                int var9;
  97.                while((var9 = this.field_0.read(var4)) != -1) {
  98.                   this.tempZip.write(var4, 0, var9);
  99.                }
  100.  
  101.                this.tempZip.closeEntry();
  102.                this.field_0.close();
  103.                super.pb.setProgress((float)(var6++));
  104.  
  105.                try {
  106.                   Thread.sleep(20L);
  107.                } catch (InterruptedException var27) {
  108.                }
  109.             }
  110.  
  111.             if (var1.size() > 0) {
  112.                this.tempZip.finish();
  113.                this.tempZip.close();
  114.                this.tempZip = null;
  115.             }
  116.          } catch (IOException var30) {
  117.             ((Throwable)var30).printStackTrace(System.out);
  118.          }
  119.  
  120.          synchronized(this){}
  121.  
  122.          try {
  123.             this.mainApp.cleanup();
  124.             File var33 = new File("temp.zip");
  125.             File var34 = new File(this.mainApp.zipFileName);
  126.             if (!var34.delete()) {
  127.                Debug.Info("delete failed.");
  128.             }
  129.  
  130.             if (!var33.renameTo(var34)) {
  131.                Debug.Info("rename failed.");
  132.             } else {
  133.                Debug.Info("rename succeeded.");
  134.             }
  135.          } catch (Throwable var29) {
  136.             throw var29;
  137.          }
  138.       } else {
  139.          try {
  140.             synchronized(this){}
  141.  
  142.             try {
  143.                this.mainApp.cleanup();
  144.                this.fos = new FileOutputStream(this.mainApp.zipFileName);
  145.                this.fos.close();
  146.             } catch (Throwable var25) {
  147.                throw var25;
  148.             }
  149.          } catch (IOException var26) {
  150.             this.mainApp.showStatus("Error: " + ((Throwable)var26).getMessage());
  151.             ((Throwable)var26).printStackTrace(System.out);
  152.          }
  153.       }
  154.  
  155.       ((Window)this).dispose();
  156.       this.mainApp.Open(this.mainApp.zipFileName);
  157.       this.mainApp.showStatus("Delete " + Integer.toString(var1.size()) + " entries completed.");
  158.    }
  159. }
  160.