Here you can find the source of decompressByteArray(byte[] compressedData)
Parameter | Description |
---|---|
compressedData | Compressed byte array (byte[]) |
public static byte[] decompressByteArray(byte[] compressedData)
//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(); } }