FileDocCategorySizeDatePackage
DirectDeflater.javaAPI DocExample1786Sun Mar 28 19:07:10 BST 1999None

DirectDeflater

public class DirectDeflater extends Object

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


       
  
    Deflater def = new Deflater();
    byte[] input = new byte[1024];
    byte[] output = new byte[1024];

    for (int i = 0; i < args.length; i++) {
    
      try {
        FileInputStream fin = new FileInputStream(args[i]);   
        FileOutputStream fout = new FileOutputStream(args[i] + DEFLATE_SUFFIX);
        
        while (true) { // read and deflate the data      

          // fill the input array
          int numRead = fin.read(input);
          if (numRead == -1) { // end of stream
            // deflate any data that remains in the input buffer
            def.finish(); 
            while (!def.finished()) {
              int numCompressedBytes = def.deflate(output, 0, output.length);
              if (numCompressedBytes > 0) {
                fout.write(output, 0, numCompressedBytes);
              } // end if
            }  // end while
            break; // exit while loop
          } // end if
          else {  // deflate the input
            def.setInput(input, 0, numRead);
            while (!def.needsInput()) {
              int numCompressedBytes = def.deflate(output, 0, output.length);
              if (numCompressedBytes > 0) {
                fout.write(output, 0, numCompressedBytes);
              } // end if
            }  // end while
          }  // end else            
        } // end while
        fin.close();
        fout.flush();
        fout.close();
        def.reset();
      } // end try
      catch (IOException e) {
        System.err.println(e);     
      } // end catch
    }