decompress byte array with gzip - Java File Path IO

Java examples for File Path IO:GZIP

Description

decompress byte array with gzip

Demo Code


//package com.java2s;
import java.io.ByteArrayInputStream;

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

public class Main {
    public static String decompress(byte[] compressed) throws IOException {
        final int BUFFER_SIZE = 32;
        ByteArrayInputStream is = new ByteArrayInputStream(compressed);
        GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE);
        StringBuilder string = new StringBuilder();
        byte[] data = new byte[BUFFER_SIZE];
        int bytesRead;
        while ((bytesRead = gis.read(data)) != -1) {
            string.append(new String(data, 0, bytesRead));
        }/*from   ww w .j a v a 2  s  .c  o  m*/
        gis.close();
        is.close();
        return string.toString();
    }
}

Related Tutorials