Java Decompress Byte Array decompressGzip(byte[] compressed)

Here you can find the source of decompressGzip(byte[] compressed)

Description

decompress Gzip

License

Apache License

Declaration

public static byte[] decompressGzip(byte[] compressed) throws IOException 

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 final int READ_BUFFER_SIZE = 1024 * 8;

    public static byte[] decompressGzip(byte[] compressed) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
        GZIPInputStream gis = new GZIPInputStream(bis);
        try {/*from  w w  w.java  2 s  . co m*/
            byte[] buffer = new byte[READ_BUFFER_SIZE];
            int read = 0;
            while ((read = gis.read(buffer)) != -1) {
                bos.write(buffer, 0, read);
            }
        } finally {
            gis.close();
        }

        return bos.toByteArray();
    }
}

Related

  1. decompressBytes(byte bytess[][])
  2. decompressBytes(byte[] input)
  3. decompressByZLIB(byte[] compressedBytes)
  4. decompressData(byte[] compressedInput)
  5. decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
  6. decompressGZIP(byte[] data)
  7. decompressGzipByteArray(byte[] compressedByteArray)
  8. decompressObject(byte[] bytes)
  9. decompressString(byte[] compressed)