Do a gzip operation. - Java File Path IO

Java examples for File Path IO:GZIP

Description

Do a gzip operation.

Demo Code


//package com.java2s;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.GZIPOutputStream;

public class Main {
    /**//from  www.  j a v  a 2s.  c o  m
     * Do a gzip operation.
     */
    public static byte[] gzip(byte[] data) {
        ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(10240);
        GZIPOutputStream output = null;
        try {
            output = new GZIPOutputStream(byteOutput);
            output.write(data);
        } catch (IOException e) {
            throw new RuntimeException("G-Zip failed.", e);
        } finally {
            if (output != null) {
                try {
                    output.close();
                } catch (IOException e) {
                }
            }
        }
        return byteOutput.toByteArray();
    }
}

Related Tutorials