Here you can find the source of ungzip(byte[] in)
Parameter | Description |
---|---|
IOException | if the input cannot be properly decompressed |
public static final byte[] ungzip(byte[] in) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPInputStream; import java.util.zip.ZipFile; public class Main { private static final int EXPECTED_COMPRESSION_RATIO = 5; private static final int BUF_SIZE = 4096; /**//from ww w . j av a 2 s .c o m * Returns an gunzipped copy of the input array. * * @throws IOException if the input cannot be properly decompressed */ public static final byte[] ungzip(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(); } /** * Closes zip file safely. */ public static void close(ZipFile zipFile) { if (zipFile != null) try { zipFile.close(); } catch (IOException ioex) { // ignore } } }