Java Decompress Byte Array decompress(byte[] str)

Here you can find the source of decompress(byte[] str)

Description

decompress

License

Open Source License

Declaration

public static byte[] decompress(byte[] str) throws Exception 

Method Source Code

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import java.util.zip.GZIPInputStream;

public class Main {
    public static byte[] decompress(byte[] str) throws Exception {
        int BUFFER = 8192;
        byte data[] = new byte[BUFFER];
        int count;
        byte out[];

        if (str == null || str.length == 0) {
            return null;
        }/* w  w w  .  j av  a  2  s.  co m*/
        System.out.println("Input byte[] length : " + str.length);
        GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(str));

        // write the files to the disk
        ByteArrayOutputStream fos = new ByteArrayOutputStream();
        while ((count = gis.read(data, 0, BUFFER)) != -1) {
            fos.write(data, 0, count);
        }
        fos.flush();
        fos.close();
        out = fos.toByteArray();

        System.out.println("Output String lenght : " + out.length);
        return out;
    }
}

Related

  1. decompress(byte[] in)
  2. decompress(byte[] input)
  3. decompress(byte[] source)
  4. decompress(byte[] source)
  5. decompress(byte[] src, Inflater decompresser, int compressCycleSize)
  6. decompress(byte[] zipByte)
  7. decompress(final byte[] compressed)
  8. decompress(final DataInputStream input, final byte[] result, int offset, int length)
  9. decompressAndB64DecodeUTF8Bytes(byte[] b64EncodedCompressedBytes)