FileDocCategorySizeDatePackage
GZipAllFiles.javaAPI DocExample1469Sat Sep 09 19:52:36 BST 2000None

GZipAllFiles

public class GZipAllFiles extends Object

Fields Summary
public static final int
THREAD_COUNT
private static int
filesToBeCompressed
Constructors Summary
Methods Summary
public static intgetNumberOfFilesToBeCompressed()

    return filesToBeCompressed;
  
public static voidmain(java.lang.String[] args)


       

    Vector pool = new Vector();
    GZipThread[] threads = new GZipThread[THREAD_COUNT];
    
    for (int i = 0; i < threads.length; i++) {
      threads[i] = new GZipThread(pool); 
      threads[i].start();
    }

    int totalFiles = 0;
    for (int i = 0; i < args.length; i++) {
      
      File f = new File(args[i]);
      if (f.exists()) {
        if (f.isDirectory()) {
          File[] files = f.listFiles();
          for (int j = 0; j < files.length; j++) {
            if (!files[j].isDirectory()) { // don't recurse directories
              totalFiles++;
              synchronized (pool) {
                pool.add(files[j]);
                pool.notifyAll();
              }
            }
          }
        } 
        else {
          totalFiles++;
          synchronized (pool) {
            pool.add(0, f);
            pool.notifyAll();
          }
        }
        
      } // end if
      
    } // end for
    
    filesToBeCompressed = totalFiles;
    
    // make sure that any waiting thread knows that no 
    // more files will be added to the pool
    for (int i = 0; i < threads.length; i++) {
      threads[i].interrupt();
    }