Java Uncompress Byte Array unzip(byte[] bytes)

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

Description

Decompresses the given byte array using the standard Java inflater (which uses the zlib compression library internally).

License

Open Source License

Declaration

public static byte[] unzip(byte[] bytes) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;

import java.util.zip.Inflater;

public class Main {
    /**//from w  w w.  ja va 2 s . c o  m
     * Decompresses the given byte array using the standard Java inflater (which
     * uses the zlib compression library internally).
     */
    public static byte[] unzip(byte[] bytes) throws Exception {
        if (bytes == null)
            return null;
        if (bytes.length == 0)
            return new byte[0];
        Inflater inflater = new Inflater();
        inflater.setInput(bytes);
        ByteArrayOutputStream out = new ByteArrayOutputStream(bytes.length);
        byte[] buffer = new byte[1024];
        while (!inflater.finished()) {
            int count = inflater.inflate(buffer);
            out.write(buffer, 0, count);
        }
        out.close();
        return out.toByteArray();
    }
}

Related

  1. degzip(byte[] compressed)
  2. uncompress(byte[] b)
  3. uncompress(byte[] input)
  4. unzip(byte zipData[])
  5. unzip(byte[] blob)
  6. unzip(byte[] bytes)
  7. unzip(byte[] bytes)
  8. unzip(byte[] bytes, String encoding)
  9. unzip(byte[] compressedByte)