duplex143 :
I'm having trouble using HttpUrlConnection. I'm working on multiple servers. Some servers send response in gzip encoding and some don't. For gzip encoding, I'm using
inputStream = new GZIPInputStream(connection.getInputStream());
inputStreamReader = new InputStreamReader(inputStream);
And for normal encoding, I'm using
inputStreamReader = new InputStreamReader(connection.getInputStream());
Is it possible to know the encoding of getInputStream so that I know beforehand whether or not to use GZIPInputStream
. Or is there a generic input stream reader for both compressed & uncompressed. Thanks.
Robby Cornelissen :
Get the content encoding from the HttpURLConnection
using getContentEncoding()
.
It it's gzip-encoded, the result of that call should be gzip
, and then you know what type of input stream you need to create.