FileDocCategorySizeDatePackage
DirectInflater.javaAPI DocExample2115Sun Mar 28 19:07:10 BST 1999None

DirectInflater

public class DirectInflater extends Object

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

  
    Inflater inf = new Inflater();
    byte[] input = new byte[1024];
    byte[] output = new byte[1024];

    for (int i = 0; i < args.length; i++) {
    
      try {
        if (!args[i].endsWith(DirectDeflater.DEFLATE_SUFFIX)) {
          System.err.println(args[i] + " does not look like a deflated file");
          continue;
        }
        FileInputStream fin = new FileInputStream(args[i]);   
        FileOutputStream fout = new FileOutputStream(args[i].substring(0, 
         args[i].length() - DirectDeflater.DEFLATE_SUFFIX.length()));
        
        while (true) { // read and inflate the data      

          // fill the input array
          int numRead = fin.read(input);
          if (numRead != -1) { // end of stream, finish inflating
            inf.setInput(input, 0, numRead);
          } // end if
          // inflate the input
            
          int numDecompressed = 0;
          while ((numDecompressed = inf.inflate(output, 0, output.length)) 
           != 0) {
            fout.write(output, 0, numDecompressed);
          }
          // at this point inflate() has returned 0
          // let's find out why
          if (inf.finished()) { // all done
            break;
          }
          else if (inf.needsDictionary()) { // we don't handle dictionaries
            System.err.println("Dictionary required! bailing...");
            break;
          }
          else if (inf.needsInput()) {
            continue;
          }
        } // end while
        
        // close up and get ready for the next file
        fin.close();
        fout.flush();
        fout.close();
        inf.reset();
      } // end try
      catch (IOException e) {
        System.err.println(e);     
      } // end catch
      catch (DataFormatException e) {
        System.err.println(args[i] + " appears to be corrupt");     
        System.err.println(e);     
      } // end catch
    }