Here you can find the source of decompressString(byte[] compressedString)
Parameter | Description |
---|---|
compressedString | The byte array to de-compress. |
public static String decompressString(byte[] compressedString)
//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(); } }