0

Since the server return the Content-Type of zipped size(gzip). I cannot get the correct bytes total for making a progress bar.

Using these two will only get the zip size Content-Length

pTransfer.getContentLength();
pTransfer.getHeaderField("Content-Length");

Is there any other approach that I can get the correct size?

Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
user1510539
  • 581
  • 1
  • 6
  • 17
  • You don't need the correct total for a progress bar. Just use 100%, and measure the consumption of the zipped stream by the unzipper code. They'll arrive at the end at about the same time. – user207421 Jun 18 '13 at 12:12
  • I don't understand. How do I do that? I am a beginner:\ – user1510539 Jun 18 '13 at 12:30

1 Answers1

0

Seems to me that it is impossible to know without copying the thing over and unzipping it. Some things can be compressed better then others and there are different compression levels that can be used. It can even be that there is compression at all.

Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
  • Then is there a way to read the actual commpressed bytes in getInputStream()? – user1510539 Jun 18 '13 at 12:05
  • See http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog – Wim Deblauwe Jun 18 '13 at 12:35
  • Are you suggesting by using URLConnection, I can read the raw bytes that is not unzipped by GZIPInputStream that HttpURLConnection does? – user1510539 Jun 18 '13 at 12:42
  • I would use `new BufferedInputStream(new GZIPInputStream(url.openStream()));`. I suppose this should work. – Wim Deblauwe Jun 18 '13 at 12:53
  • But I have to send some data to the server(POST) in order to get the required stream. Directly openning a stream from url won't work. – user1510539 Jun 18 '13 at 12:59