// From http://code.calum.org/ /* * Heavily borrowed from the code here: * http://www.java-tips.org/java-se-tips/java.util.zip/how-to-decompress-a-byte-array.html * */ public static byte[] decompressByteArray(byte[] compressedData ) { int startBytes = compressedData.length; // System.out.println("decompressByteArray: input size is " + startBytes); // 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) { } } try { bos.close(); } catch (IOException e) { } // Get the decompressed data byte[] decompressedData = bos.toByteArray(); int endBytes = decompressedData.length; // System.out.println("decompressByteArray: output is " + endBytes + " bytes"); // System.out.println("Ratio: " + (( 100D / startBytes ) * endBytes) + "%"); return decompressedData; }