Android: Gzip/Http supported by default?

Posted by OneWorld on Stack Overflow See other posts from Stack Overflow or by OneWorld
Published on 2010-09-06T12:54:31Z Indexed on 2012/11/01 11:01 UTC
Read the original article Hit count: 185

Filed under:
|

I am using the code shown below to get Data from our server where Gzip is turned on. Does my Code already support Gzip (maybe this is already done by android and not by my java program) or do I have to add/change smth.? How can I check that it's using Gzip? For my opionion the download is kinda slow.

private static InputStream OpenHttpConnection(String urlString) throws IOException {
        InputStream in = null;
        int response = -1;

        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();

        if (!(conn instanceof HttpURLConnection))
          throw new IOException("Not an HTTP connection");

        try {
          HttpURLConnection httpConn = (HttpURLConnection) conn;
          httpConn.setAllowUserInteraction(false);
          httpConn.setInstanceFollowRedirects(true);
          httpConn.setRequestMethod("GET");
          httpConn.connect();

          response = httpConn.getResponseCode();
          if (response == HttpURLConnection.HTTP_OK) {
            in = httpConn.getInputStream();
            if(in == null)
              throw new IOException("No data");
          }
        } catch (Exception ex) {
          throw new IOException("Error connecting");
        }
        return in;
      }

© Stack Overflow or respective owner

Related posts about android

Related posts about gzipstream