Here you can find the source of gunzip(byte[] bytes)
Parameter | Description |
---|---|
bytes | The compressed bytes. |
Parameter | Description |
---|---|
IOException | if an I/O error occurs. |
public static byte[] gunzip(byte[] bytes) 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.io.InputStream; import java.util.zip.GZIPInputStream; public class Main { /**//w ww . j av a 2 s .c om * Uncompresses a GZIP file. * @param bytes The compressed bytes. * @return The uncompressed bytes. * @throws IOException if an I/O error occurs. */ public static byte[] gunzip(byte[] bytes) throws IOException { /* create the streams */ try (InputStream is = new GZIPInputStream(new ByteArrayInputStream( bytes))) { try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { /* copy data between the streams */ byte[] buf = new byte[4096]; int len; while ((len = is.read(buf, 0, buf.length)) != -1) { os.write(buf, 0, len); } /* return the uncompressed bytes */ return os.toByteArray(); } } } }