以下に示すコードを使用して、Gzipがオンになっているサーバーからデータを取得しています。私のコードはすでにGzipをサポートしていますか(おそらくこれは私のJavaプログラムではなくAndroidによってすでに行われています)、またはsmthを追加/変更する必要がありますか?Gzipを使用していることを確認するにはどうすればよいですか?私の意見では、ダウンロードは少し遅いです。
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;
}