java - How to get the size of gzip compressed data from HttpURLConnection -
java - How to get the size of gzip compressed data from HttpURLConnection -
im trying fetch length of info urlconnection.
since im measuring how much info transferred, dont want know size of uncompressed data, compressed one. unfortunately inputstream automatically decompresses gzip compressed data.
i have manually download whole file, in case output chunked , cant length via connection.getcontentlength();
the code here
try { connection = (httpurlconnection) (new url(url)).openconnection(); connection.connect(); int contentlength = connection.getcontentlength(); if (contentlength == -1 && connection != null) { inputstream input = connection.getinputstream(); byte[] buffer = new byte[4096]; int count = 0, len; while ((len = input.read(buffer)) > 0) { count += len; } contentlength = count; } totalsize += contentlength; }
you can see illustration file: http://www.google-analytics.com/analytics.js when check header in chrome says content-length: 11181. unable content length urlconnection (it returns -1) effort download file. however, output 25421 bytes, size of uncompressed file.
thank kind of help.
java android
Comments
Post a Comment