Java Uncompress Byte Array unzip(byte[] bytes)

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

Description

unzip

License

Apache License

Declaration

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

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 {
    public static byte[] unzip(byte[] bytes) {
        try {//from  w ww.j  a va 2s. c om
            GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buff = new byte[512];
            int read = gis.read(buff);
            while (read > 0) {
                bos.write(buff, 0, read);
                read = gis.read(buff);
            }
            gis.close();
            bos.close();
            return bos.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new byte[0];
    }
}

Related

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