Java Ungzip Byte Array unGZip(byte[] bContent)

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

Description

un G Zip

License

Open Source License

Declaration

public static byte[] unGZip(byte[] bContent) throws IOException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayInputStream;

import java.io.DataInputStream;

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

public class Main {
    private static final int MAXLENGTH = 102400;
    private static final int BUFFERSIZE = 1024;

    public static byte[] unGZip(byte[] bContent) throws IOException {

        byte[] data = new byte[MAXLENGTH];
        try {/*from ww w  .  j  av  a2  s  .  c  o  m*/
            ByteArrayInputStream in = new ByteArrayInputStream(bContent);
            GZIPInputStream pIn = new GZIPInputStream(in);
            DataInputStream objIn = new DataInputStream(pIn);

            int len = 0;
            int count = 0;
            while ((count = objIn.read(data, len, len + BUFFERSIZE)) != -1) {
                len = len + count;
            }

            byte[] trueData = new byte[len];
            System.arraycopy(data, 0, trueData, 0, len);

            objIn.close();
            pIn.close();
            in.close();

            return trueData;

        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
    }
}

Related

  1. ungzip(byte[] buff)
  2. ungzip(byte[] bytes)
  3. unGZip(byte[] bytes)
  4. unGzip(byte[] data)