Java Gunzip Byte Array gunzip(byte[] bytes)

Here you can find the source of gunzip(byte[] bytes)

Description

Decompresses the given byte array in the GZIP file format.

License

Open Source License

Declaration

public static byte[] gunzip(byte[] bytes) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.zip.GZIPInputStream;

public class Main {
    /**/* w  w  w.  j  a  v  a2s  . co  m*/
     * Decompresses the given byte array in the GZIP file format.
     */
    public static byte[] gunzip(byte[] bytes) throws IOException {
        if (bytes == null)
            return null;
        if (bytes.length == 0)
            return new byte[0];
        ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
        byte[] result = null;
        try (GZIPInputStream gzip = new GZIPInputStream(bin);
                ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
            byte[] buffer = new byte[1024];
            int count = -1;
            while ((count = gzip.read(buffer)) >= 0)
                bout.write(buffer, 0, count);
            result = bout.toByteArray();
        }
        return result;
    }
}

Related

  1. gunzip(byte src[], byte default_value[])
  2. gunzip(byte[] bytes)
  3. gunzip(byte[] bytes)
  4. gunzip(byte[] contentBytes)
  5. gunzip(byte[] data)
  6. gunzip(byte[] data)