Android Byte Array Unzip decompress(byte[] paramArrayOfByte)

Here you can find the source of decompress(byte[] paramArrayOfByte)

Description

decompress

Declaration

public static byte[] decompress(byte[] paramArrayOfByte)
            throws Exception 

Method Source Code

//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPInputStream;

public class Main {
    public static String decompress(String paramString) throws Exception {
        return new String(decompress(paramString.getBytes("utf-8")),
                "utf-8");
    }//  w w  w. j av  a2 s. c  o  m

    public static byte[] decompress(byte[] paramArrayOfByte)
            throws Exception {
        ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(
                paramArrayOfByte);
        GZIPInputStream localGZIPInputStream = new GZIPInputStream(
                localByteArrayInputStream);
        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
        byte[] arrayOfByte = new byte[1024];
        for (;;) {
            int i = localGZIPInputStream.read(arrayOfByte, 0, 1024);
            if (i == -1) {
                localByteArrayInputStream.close();
                localByteArrayOutputStream.flush();
                localByteArrayOutputStream.close();
                localGZIPInputStream.close();
                return localByteArrayOutputStream.toByteArray();
            }
            localByteArrayOutputStream.write(arrayOfByte, 0, i);
        }
    }
}

Related

  1. decompress(byte[] data)
  2. decompress(byte[] data)
  3. deflate(byte[] paramArrayOfByte)
  4. deflate(byte[] paramArrayOfByte, int paramInt1, int paramInt2)