Android Unzip Byte Array unzip(byte[] zipBytes)

Here you can find the source of unzip(byte[] zipBytes)

Description

unzip

Declaration

public static byte[] unzip(byte[] zipBytes) throws IOException 

Method Source Code

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

import java.io.IOException;

import java.util.zip.ZipInputStream;

public class Main {
    public static byte[] unzip(byte[] zipBytes) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(zipBytes);
        ZipInputStream zis = new ZipInputStream(bais);
        zis.getNextEntry();/*from  w  w w  .  j a v a 2 s .com*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final int BUFSIZ = 4096;
        byte inbuf[] = new byte[BUFSIZ];
        int n;
        try {
            while ((n = zis.read(inbuf, 0, BUFSIZ)) != -1) {
                baos.write(inbuf, 0, n);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        byte[] data = baos.toByteArray();
        zis.close();
        return data;
    }
}

Related

  1. unZipByteToString(byte[] data)
  2. unZipByte(byte[] data)