FileDocCategorySizeDatePackage
ZipThread.javaAPI DocExample1511Sun Dec 12 10:51:34 GMT 2004None

ZipThread

public class ZipThread extends Thread

Fields Summary
private List
pool
Constructors Summary
public ZipThread(List pool)

    this.pool = pool;
  
Methods Summary
public voidrun()

    
    while (true) {
    
      File input = null;
      
      synchronized (pool) {         
        while (pool.isEmpty()) {
          try {
            pool.wait();
          }
          catch (InterruptedException e) {
          }
        }

        input = (File) pool.remove(pool.size()-1); 
      
      }
    
      // don't compress an already compressed file
      if (!input.getName().endsWith(".gz")) { 
      
        try {
          InputStream in = new FileInputStream(input);
          in = new BufferedInputStream(in);
          
          // possible NullPointerException here????
          File output = new File(input.getParent(), input.getName() + ".gz");
          if (!output.exists()) { // Don't overwrite an existing file
            OutputStream out = new FileOutputStream(output);
            out = new GZIPOutputStream(out);
            out = new BufferedOutputStream(out);
            int b;
            while ((b = in.read()) != -1) out.write(b);
            out.flush();
            out.close();
            in.close();
          }
        }
        catch (IOException e) {
          System.err.println(e);
        }
        
      } // end if 
  
    } // end while