Java Decompress Byte Array decompressByZLIB(byte[] compressedBytes)

Here you can find the source of decompressByZLIB(byte[] compressedBytes)

Description

Uncompresses the given byte array by the ZLIB algorithm.

License

Open Source License

Parameter

Parameter Description
compressedBytes Compressed bytes

Return

Uncompressed bytes

Declaration

public static byte[] decompressByZLIB(byte[] compressedBytes) 

Method Source Code

//package com.java2s;
//   The MIT License

import java.io.ByteArrayOutputStream;

import java.util.zip.Inflater;

public class Main {
    /**/*from www . ja  v a 2s.com*/
     * Uncompresses the given byte array by the ZLIB algorithm.
     * @param  compressedBytes Compressed bytes
     * @return                 Uncompressed bytes
     */
    public static byte[] decompressByZLIB(byte[] compressedBytes) {
        try {
            Inflater inflater = new Inflater();
            inflater.setInput(compressedBytes);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(
                    compressedBytes.length);
            byte[] buffer = new byte[1024];
            while (!inflater.finished()) {
                int count = inflater.inflate(buffer);
                byteArrayOutputStream.write(buffer, 0, count);
            }
            byteArrayOutputStream.close();
            return byteArrayOutputStream.toByteArray();

        } catch (Exception exception) {
            throw new IllegalStateException(exception.getMessage());
        }
    }
}

Related

  1. decompressAndB64DecodeUTF8Bytes(byte[] b64EncodedCompressedBytes)
  2. decompressByte(byte[] decompress)
  3. decompressByteArray(byte[] compressedData)
  4. decompressBytes(byte bytess[][])
  5. decompressBytes(byte[] input)
  6. decompressData(byte[] compressedInput)
  7. decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
  8. decompressGzip(byte[] compressed)
  9. decompressGZIP(byte[] data)