Java Decompress Byte Array decompressByteArray(byte[] compressedData)

Here you can find the source of decompressByteArray(byte[] compressedData)

Description

Decompress a byte array (byte[])

License

Open Source License

Parameter

Parameter Description
compressedData Compressed byte array (byte[])

Return

Raw byte array (byte[])

Declaration

public static byte[] decompressByteArray(byte[] compressedData) 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;

import java.util.zip.DataFormatException;

import java.util.zip.Inflater;

public class Main {
    /**/*w  ww.ja  va 2s.  c  o m*/
     * Decompress a byte array (byte[])
     * @param compressedData Compressed byte array (byte[])
     * @return Raw byte array (byte[])
     */
    public static byte[] decompressByteArray(byte[] compressedData) {
        // Create the decompressor and give it the data to compress
        Inflater decompressor = new Inflater();
        decompressor.setInput(compressedData);

        // Create an expandable byte array to hold the decompressed data
        ByteArrayOutputStream bos = new ByteArrayOutputStream(
                compressedData.length);

        // Decompress the data
        byte[] buf = new byte[1024];
        while (!decompressor.finished()) {
            try {
                int count = decompressor.inflate(buf);
                bos.write(buf, 0, count);
            } catch (DataFormatException e) {
                throw new RuntimeException(
                        "This byte array is not a valid compressed data", e);
            }
        }

        // Get the decompressed data
        return bos.toByteArray();
    }
}

Related

  1. decompress(byte[] zipByte)
  2. decompress(final byte[] compressed)
  3. decompress(final DataInputStream input, final byte[] result, int offset, int length)
  4. decompressAndB64DecodeUTF8Bytes(byte[] b64EncodedCompressedBytes)
  5. decompressByte(byte[] decompress)
  6. decompressBytes(byte bytess[][])
  7. decompressBytes(byte[] input)
  8. decompressByZLIB(byte[] compressedBytes)
  9. decompressData(byte[] compressedInput)