// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

public class GZipFun {
    public static void gzip(String infnm, String outfnm) throws IOException {
        FileInputStream is = new FileInputStream(infnm);
        GZIPOutputStream os = new GZIPOutputStream(new FileOutputStream(outfnm));
        byte[] b = new byte[100000];
        int n;
        while((n = is.read(b)) > 0) {
            os.write(b, 0, n);
        }
        os.close();
        is.close();
    }
    public static void xgzip(String infnm, String outfnm, int level) throws IOException {
        FileInputStream is = new FileInputStream(infnm);
        XGZIPOutputStream os = new XGZIPOutputStream(new FileOutputStream(outfnm));
        os.setLevel(level);
        byte[] b = new byte[100000];
        int n;
        while((n = is.read(b)) > 0) {
            os.write(b, 0, n);
        }
        os.close();
        is.close();
    }
    public static void main(String[] args) throws Exception {
        gzip("C:\\z.txt", "C:\\z.txt.gz");
        for(int i = 0; i < 10; i++) {
            xgzip("C:\\z.txt", "C:\\z.txt.gz" + i, i);
        }
    }
}

class XGZIPOutputStream extends GZIPOutputStream {
    public XGZIPOutputStream(OutputStream out) throws IOException {
        super(out);
    }
    public void setLevel(int level) {
        def.setLevel(level);
    }
}
