Java Decompress Byte Array decompress(byte[] byteArray)

Here you can find the source of decompress(byte[] byteArray)

Description

decompress

License

Apache License

Declaration

public static String decompress(byte[] byteArray) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.zip.GZIPInputStream;

public class Main {
    /** the platform specific EOL */
    static private String eol = String.format("%n");

    public static final String decompress(InputStream compressedStream) throws IOException {
        GZIPInputStream decompressedStream = new GZIPInputStream(compressedStream);
        return readStream(decompressedStream);
    }//w  w w .  java 2 s  .c  om

    public static String decompress(String string) throws IOException {
        return decompress(new ByteArrayInputStream(string.getBytes()));
    }

    public static String decompress(byte[] byteArray) throws IOException {
        return decompress(new ByteArrayInputStream(byteArray));
    }

    public static final String readStream(InputStream stream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        try {
            StringBuilder result = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                if (result.length() > 0) {
                    result.append(eol);
                }
                result.append(line);
            }
            return result.toString();
        } finally {
            reader.close();
        }
    }
}

Related

  1. decompress(byte[] bytes)
  2. Decompress(byte[] bytes)
  3. decompress(byte[] bytes)
  4. decompress(byte[] bytes)