Android Http Ungzip unGzip(HttpEntity entity)

Here you can find the source of unGzip(HttpEntity entity)

Description

un Gzip

Declaration

public static String unGzip(HttpEntity entity) 

Method Source Code

//package com.java2s;
import android.util.Log;
import org.apache.http.HttpEntity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;

public class Main {
    private static final String UTF = "UTF-8";
    private static final String TAG = "GzipUtils";

    public static String unGzip(HttpEntity entity) {
        StringBuilder inputStringBuilder = new StringBuilder();
        BufferedReader bufferedReader;
        String charset = UTF;//  w w w  . j  a  v a  2s  .  c o m
        String line;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(
                    new GZIPInputStream(entity.getContent()), charset));
            line = bufferedReader.readLine();

            while (line != null) {
                inputStringBuilder.append(line);
                line = bufferedReader.readLine();
            }

        } catch (IOException e) {
            Log.e(TAG, e.getMessage());
        }

        return inputStringBuilder.toString();
    }
}