Java Uncompress Byte Array unzip(byte[] output)

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

Description

unzip

License

Apache License

Declaration

public static byte[] unzip(byte[] output) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

public class Main {
    private static final int BUFFER_SIZE = 256;

    public static byte[] unzip(byte[] output) {
        if (output == null || output.length == 0) {
            return output;
        }/* ww w  . j  a v  a  2s  .  c  o m*/
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ByteArrayInputStream in = new ByteArrayInputStream(output);
            GZIPInputStream gunzip = new GZIPInputStream(in);
            byte[] buffer = new byte[BUFFER_SIZE];
            int ret;
            while ((ret = gunzip.read(buffer)) >= 0) {
                out.write(buffer, 0, ret);
            }
            gunzip.close();
            return out.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. unZip(byte[] data)
  2. unzip(byte[] data)
  3. unzip(byte[] datas)
  4. unzip(byte[] in)
  5. unZip(byte[] input)
  6. unzip(byte[] src)
  7. unzip(byte[] zipData, File directory)
  8. unZip(byte[] zipFile)