1

Possible Duplicate:
Android: HTTP communication should use “Accept-Encoding: gzip”

My Android application downloads temp.bin file but today it (file) too big. I configured Apache to compress it to temp.bin.gz by using gzip. So i got 10% from actual size.

So far so good. Now the problem is how to decompress it in Android side during downloading.

I used before this snippets of download algorithm:

    URL url = new URL(urlStr);

        // set redirect mode ...        
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setInstanceFollowRedirects(true);

        connection.setConnectTimeout(0);
        connection.setReadTimeout(0);
        connection.setUseCaches(false);
        connection.setAllowUserInteraction(false);

        connection.connect();  

                    ....

InputStream in = null;
        //boolean lengthValid = (contentLength != -1); 

        byte    bytes[] = new byte[256];
        int     total_count = 0;
        int     max_count = 0;

        try {
            in = connection.getInputStream();
            int count = 0;


            while (count != -1){
                count = in.read(bytes);
  ....

Any and all suggestions would be greatly appreciated.

Community
  • 1
  • 1
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
  • 1
    Use a [GZIPInputStream](http://developer.android.com/reference/java/util/zip/GZIPInputStream.html) to wrap your stream? Check this [answer](http://stackoverflow.com/a/1576513/967142) – Jens Nov 12 '12 at 08:36

1 Answers1

2

Simply use java.util.zip.GZIPInputStream instead of InputStream

Also See

Abhishek Nandi
  • 4,265
  • 1
  • 30
  • 43