Java Decompress Byte Array decompress(byte[] bytes)

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

Description

decompress

License

Open Source License

Parameter

Parameter Description
bytes bytes to be decompressed

Exception

Parameter Description
IOException an exception

Return

a decompressed String

Declaration

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

Method Source Code


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

import java.io.IOException;
import java.io.InputStreamReader;

import java.util.zip.GZIPInputStream;

public class Main {
    /**/*  ww w.  j  a  v  a2 s . c o m*/
     * 
     * @param bytes
     *          bytes to be decompressed
     * @return a decompressed String
     * @throws IOException
     */
    public static String decompress(byte[] bytes) throws IOException {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
        BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
        String outStr = "";
        String line;
        while ((line = bf.readLine()) != null) {
            outStr += line;
        }
        return outStr;
    }
}

Related

  1. decompress(byte[] byteArray)
  2. decompress(byte[] bytes)
  3. decompress(byte[] bytes)
  4. Decompress(byte[] bytes)
  5. decompress(byte[] bytes)
  6. decompress(byte[] bytes)
  7. decompress(byte[] bytes, int bufferSize)
  8. decompress(byte[] compressed)
  9. decompress(byte[] compressed)