Here you can find the source of degzip(byte[] compressed)
Parameter | Description |
---|---|
compressed | The compressed buffer. |
Parameter | Description |
---|---|
IOException | If there is an error decompressing the buffer. |
public static byte[] degzip(byte[] compressed) 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 w w .j av a 2 s. c o m*/ * Degzips <strong>all</strong> of the datain the specified {@link ByteBuffer}. * * @param compressed The compressed buffer. * @return The decompressed array. * @throws IOException If there is an error decompressing the buffer. */ public static byte[] degzip(byte[] compressed) throws IOException { try (InputStream is = new GZIPInputStream(new ByteArrayInputStream(compressed)); ByteArrayOutputStream out = new ByteArrayOutputStream()) { byte[] buffer = new byte[1024]; while (true) { int read = is.read(buffer, 0, buffer.length); if (read == -1) { break; } out.write(buffer, 0, read); } return out.toByteArray(); } } }