unGzip byte array and return byte array - Android File Input Output

Android examples for File Input Output:Zip File

Description

unGzip byte array and return byte array

Demo Code


//package com.java2s;

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

import java.util.zip.GZIPInputStream;

public class Main {
    public static byte[] unzip(byte[] zipData) {
        try {//from   ww w  . j  a va  2 s  .c om
            ByteArrayOutputStream os = new ByteArrayOutputStream();

            ByteArrayInputStream inputstream = new ByteArrayInputStream(
                    zipData);
            GZIPInputStream v3_1 = new GZIPInputStream(inputstream);
            int count;
            byte dsata[] = new byte[1024];
            while ((count = v3_1.read(dsata, 0, 1024)) != -1) {
                os.write(dsata, 0, count);
            }
            v3_1.close();
            return os.toByteArray();
        } catch (Exception e) {
            return null;
        }

    }
}

Related Tutorials