Compresses a byte array gzip - Java File Path IO

Java examples for File Path IO:GZIP

Description

Compresses a byte array gzip

Demo Code


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class Main{
    /**//from  w  w  w . j  ava2  s. com
     * Compresses a byte array
     */
    public static byte[] uncompress(byte[] theBytes) throws IOException {
        ByteArrayInputStream bis = new ByteArrayInputStream(theBytes);
        GZIPInputStream gos = new GZIPInputStream(bis);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        IOUtils.copy(gos, bos);
        return bos.toByteArray();
    }
}

Related Tutorials