Android Unzip Byte Array unZipByte(byte[] data)

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

Description

un Zip Byte

Declaration

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

Method Source Code

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

import java.util.zip.Inflater;

public class Main {
    private final static int CacheSize = 1024;

    public static byte[] unZipByte(byte[] data) {
        Inflater decompresser = new Inflater();
        decompresser.setInput(data);/* ww  w.j  av a  2  s.c o m*/
        byte result[] = new byte[0];
        ByteArrayOutputStream o = new ByteArrayOutputStream(1);
        try {
            byte[] buf = new byte[CacheSize];
            int got = 0;
            while (!decompresser.finished()) {
                got = decompresser.inflate(buf);
                o.write(buf, 0, got);
            }
            result = o.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                o.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            decompresser.end();
        }
        return result;
    }
}

Related

  1. unZipByteToString(byte[] data)
  2. unzip(byte[] zipBytes)