public static InputStream getGzipStream(String url) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(url);
request.addHeader("Accept-Encoding", "gzip");
HttpResponse response = httpclient.execute(request);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return null;
}
InputStream instream = response.getEntity().getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null
&& contentEncoding.getValue().equalsIgnoreCase("gzip")) {
instream = new GZIPInputStream(instream);
}
return instream;
}
No comments:
Post a Comment