Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.InputStreamReader;

import java.io.Reader;

import java.util.zip.GZIPInputStream;

public class Main {
    public static String descomprimeComGZIP(byte[] bytes, String encoding) {
        String decompressedString = "";
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            GZIPInputStream gzip = new GZIPInputStream(bais);
            Reader reader = new InputStreamReader(gzip, encoding);
            StringBuffer sbuf = new StringBuffer();
            char[] buffer = new char[32 * 1024];
            int nread;
            while ((nread = reader.read(buffer)) >= 0) {
                sbuf.append(buffer, 0, nread);
            }
            decompressedString = sbuf.toString();
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return decompressedString;
    }
}