GZIPInputStream

import java.io.*;
import java.util.zip.*;
import com.macfaq.io.*;


public class GUnzipper {

  public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
      if (args[i].toLowerCase().endsWith(GZipper.GZIP_SUFFIX)) {
        try {
          FileInputStream fin = new FileInputStream(args[i]);      
          GZIPInputStream in = new GZIPInputStream(fin);
          FileOutputStream out = new FileOutputStream(
           args[i].substring(0, args[i].length()-3));
          byte[] buffer = new byte[256];
          while (true) {
            int bytesRead = in.read(buffer);
            if (bytesRead == -1) break;
            out.write(buffer, 0, bytesRead);
          }        
          out.close();
        }
        catch (IOException e) {
          System.err.println(e);     
        }
      }
      else {
        System.err.println(args[i] + " does not appear to be a gzipped file.");
      }
    }

  }

}


Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified March 17, 2000