Java Uncompress Byte Array degzip(byte[] compressed)

Here you can find the source of degzip(byte[] compressed)

Description

Degzips all of the datain the specified ByteBuffer .

License

Open Source License

Parameter

Parameter Description
compressed The compressed buffer.

Exception

Parameter Description
IOException If there is an error decompressing the buffer.

Return

The decompressed array.

Declaration

public static byte[] degzip(byte[] compressed) throws IOException 

Method Source Code


//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();
        }
    }
}

Related

  1. uncompress(byte[] b)
  2. uncompress(byte[] input)
  3. unzip(byte zipData[])
  4. unzip(byte[] blob)