Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.*;
import java.util.zip.*;

public class Main {
    /**
     * Decompresses a array of bytes back into a string.
     *
     * @param bytes The compressed list of bytes.
     *
     * @return The string uncompress.
     *
     * @throws Exception If failed to uncompress.
     */
    public static String decompress(byte[] bytes) throws Exception {
        if (bytes == null || bytes.length == 0) {
            return null;
        }

        GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
        BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
        StringBuilder result = new StringBuilder();
        String line;

        while ((line = bf.readLine()) != null) {
            result.append(line);
        }

        return result.toString();
    }
}