Example usage for java.util.zip GZIPInputStream available

List of usage examples for java.util.zip GZIPInputStream available

Introduction

In this page you can find the example usage for java.util.zip GZIPInputStream available.

Prototype

public int available() throws IOException 

Source Link

Document

Returns 0 after EOF has been reached, otherwise always return 1.

Usage

From source file:Main.java

public static byte[] gzipDecodeByteArray(byte[] data) {
    GZIPInputStream gzipInputStream = null;
    try {//  w  w  w .j a  va 2s.  c  o  m
        gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(data));

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
        byte[] buffer = new byte[1024];
        while (gzipInputStream.available() > 0) {
            int count = gzipInputStream.read(buffer, 0, 1024);
            if (count > 0) {
                //System.out.println("Read " + count + " bytes");
                outputStream.write(buffer, 0, count);
            }
        }

        outputStream.close();
        gzipInputStream.close();
        return outputStream.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:net.ulno.jpunch.util.Util.java

public static byte[] unzip(byte[] data) throws IOException {
    InputStream is = new ByteArrayInputStream(data);
    GZIPInputStream gz = new GZIPInputStream(is);
    List<Byte> l = new ArrayList<Byte>();
    while (gz.available() != 0)
        l.add((byte) gz.read());
    // last byte is unnecessary (it is -1)
    byte[] uncmp = new byte[l.size() - 1];
    for (int i = 0; i < l.size() - 1; i++)
        uncmp[i] = l.get(i);//w w  w  . j  a va2s. c  o  m
    return uncmp;
}

From source file:nl.nn.adapterframework.util.Misc.java

public static byte[] gunzip(byte[] input) throws DataFormatException, IOException {

    // Create an expandable byte array to hold the decompressed data
    ByteArrayInputStream bis = new ByteArrayInputStream(input);
    GZIPInputStream gz = new GZIPInputStream(bis);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);

    // Decompress the data
    byte[] buf = new byte[1024];
    while (gz.available() > 0) {
        int count = gz.read(buf, 0, 1024);
        if (count > 0) {
            bos.write(buf, 0, count);//from   ww  w.ja  va2s .c om
        }
    }
    bos.close();

    // Get the decompressed data
    return bos.toByteArray();
}