Here you can find the source of unzip(byte[] in)
Parameter | Description |
---|---|
IOException | if the input cannot be properly decompressed |
public static final byte[] unzip(byte[] in) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; public class Main { private static final int EXPECTED_COMPRESSION_RATIO = 5; private static final int BUF_SIZE = 4096; /**//from ww w .jav a 2 s . com * Returns an gunzipped copy of the input array. * @throws IOException if the input cannot be properly decompressed */ public static final byte[] unzip(byte[] in) throws IOException { // decompress using GZIPInputStream ByteArrayOutputStream outStream = new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length); GZIPInputStream inStream = new GZIPInputStream(new ByteArrayInputStream(in)); byte[] buf = new byte[BUF_SIZE]; while (true) { int size = inStream.read(buf); if (size <= 0) break; outStream.write(buf, 0, size); } outStream.close(); return outStream.toByteArray(); } }