Java Gunzip Byte Array gunzip(byte[] data)

Here you can find the source of gunzip(byte[] data)

Description

Do a g-unzip operation.

License

Apache License

Declaration

public static byte[] gunzip(byte[] data) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

public class Main {
    /**//from w  w w . ja va 2  s .  co m
     * Do a g-unzip operation.
     */
    public static byte[] gunzip(byte[] data) {
        ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(10240);
        GZIPInputStream input = null;
        try {
            input = new GZIPInputStream(new ByteArrayInputStream(data));
            byte[] buffer = new byte[1024];
            int n = 0;
            for (;;) {
                n = input.read(buffer);
                if (n <= 0)
                    break;
                byteOutput.write(buffer, 0, n);
            }
        } catch (IOException e) {
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException ioe) {
                }
            }
        }
        return byteOutput.toByteArray();
    }
}

Related

  1. gunzip(byte src[], byte default_value[])
  2. gunzip(byte[] bytes)
  3. gunzip(byte[] bytes)
  4. gunzip(byte[] bytes)
  5. gunzip(byte[] contentBytes)
  6. gunzip(byte[] data)
  7. gunzip(byte[] data)
  8. gunzip(byte[] in)
  9. gunzip(final byte[] b, final Class c)