Java Decompress Byte Array decompressString(byte[] compressedString)

Here you can find the source of decompressString(byte[] compressedString)

Description

De-compresses a GZip compressed byte array.

License

Open Source License

Parameter

Parameter Description
compressedString The byte array to de-compress.

Return

A string of the de-compressed data.

Declaration

public static String decompressString(byte[] compressedString) 

Method Source Code

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

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.zip.GZIPInputStream;

public class Main {
    /**//from w  w  w  . j a v  a  2s .  c  o  m
     * De-compresses a GZip compressed byte array. Expects UTF-8 encoding.
     * 
     * @param compressedString The byte array to de-compress.
     * @return A string of the de-compressed data.
     */
    public static String decompressString(byte[] compressedString) {
        ByteArrayInputStream bis = new ByteArrayInputStream(compressedString);
        GZIPInputStream gis;
        StringBuilder sb = new StringBuilder();

        try {
            gis = new GZIPInputStream(bis);
            BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));

            String line;

            while ((line = br.readLine()) != null) {
                sb.append(line);
            }

            br.close();
            gis.close();
            bis.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return sb.toString();
    }
}

Related

  1. decompressGZIP(byte[] data)
  2. decompressGzipByteArray(byte[] compressedByteArray)
  3. decompressObject(byte[] bytes)
  4. decompressString(byte[] compressed)
  5. decompressString(byte[] compressedData)
  6. decompressStringFromByteArray(byte[] compressedString)