UnGzip an gzipped input stream to an output stream. - Java File Path IO

Java examples for File Path IO:GZIP

Description

UnGzip an gzipped input stream to an output stream.

Demo Code


//package com.java2s;

import java.io.IOException;

import java.io.OutputStream;
import java.util.zip.GZIPInputStream;

public class Main {
    /**/*  w  w  w . ja  va 2s.c o m*/
     * UnGzip an gzipped input stream to an output stream. You need to close streams manually.
     * @param gzippedInputStream
     * @param ungzippedOutputStream
     * @throws IOException
     */
    public static void unGzip(GZIPInputStream gzippedInputStream,
            OutputStream ungzippedOutputStream) throws IOException {
        byte[] buffer = new byte[1024];
        int len = -1;
        while ((len = gzippedInputStream.read(buffer)) != -1) {
            ungzippedOutputStream.write(buffer, 0, len);
        }
    }
}

Related Tutorials