Java Ungzip Byte Array unGZip(byte[] data)

Here you can find the source of unGZip(byte[] data)

Description

un G Zip

License

Apache License

Declaration

public static byte[] unGZip(byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static byte[] unGZip(byte[] data) {
        byte[] b = null;
        try {/*from  ww  w .  jav a  2s.com*/
            ByteArrayInputStream bis = new ByteArrayInputStream(data);
            GZIPInputStream gzip = new GZIPInputStream(bis);
            byte[] buf = new byte[1024];
            int num = -1;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((num = gzip.read(buf, 0, buf.length)) != -1) {
                baos.write(buf, 0, num);
            }
            b = baos.toByteArray();
            baos.flush();
            baos.close();
            gzip.close();
            bis.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return b;
    }
}

Related

  1. unGZip(byte[] bContent)
  2. ungzip(byte[] buff)
  3. unGZip(byte[] bytes)
  4. ungzip(byte[] bytes)
  5. unGzip(byte[] data)
  6. ungzip(byte[] in)
  7. unGzip(byte[] str, String charset)
  8. ungzipBestEffort(byte[] in)
  9. ungzipBuffer(byte[] bufInput)