FileDocCategorySizeDatePackage
Zipper.javaAPI DocExample1458Sun Mar 28 19:07:28 BST 1999None

Zipper

public class Zipper extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  
    if (args.length < 2) {
      System.out.println("Usage: java Zipper [-d level] name.zip file1 file2...");
      return; 
    }
    
    String outputFile = args[0];
    // maximum compression is our default
    int level = 9;
    int start = 1;
    if (args[0].equals("-d")) {
      try {
        level = Integer.parseInt(args[1]);
        outputFile = args[2];
        start = 3;
      }
      catch (Exception e) {
        System.out.println("Usage: java Zipper [-d level] name.zip file1 file2...");
        return;         
      }
    }    
    
    try {
      FileOutputStream fout = new FileOutputStream(outputFile);
      ZipOutputStream zout = new ZipOutputStream(fout);
      zout.setLevel(level);
      for (int i = start; i < args.length; i++) {
        ZipEntry ze = new ZipEntry(args[i]);
        try {
          System.out.println("Compressing " + args[i]);
          FileInputStream fin = new FileInputStream(args[i]);
          zout.putNextEntry(ze);
          StreamCopier.copy(fin, zout);
          zout.closeEntry();
          fin.close();
        }
        catch (IOException e) {
          System.err.println(e);    
        }
      }
      zout.close();    
    }
    catch (Exception e) {
      System.err.println(e);
    }