Created
January 12, 2016 17:09
-
-
Save evanhalley/c3a948fb9b227e59716b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConnectionStreamDetectionExample { | |
/** | |
* Returns the correct input stream based on the content encoding | |
* @param connection | |
* @return | |
* @throws IOException | |
*/ | |
private static InputStream getInputStream(HttpURLConnection connection) throws IOException { | |
InputStream inputStream = null; | |
if (connection.getContentEncoding() != null) { | |
if (connection.getContentEncoding().equalsIgnoreCase("gzip") || | |
connection.getContentEncoding().equalsIgnoreCase("x-gzip")) { | |
inputStream = new GZIPInputStream(connection.getInputStream()); | |
} else if (connection.getContentEncoding().equalsIgnoreCase("deflate")) { | |
inputStream = new DeflaterInputStream(connection.getInputStream()); | |
} | |
} | |
if (inputStream == null) { | |
inputStream = connection.getInputStream(); | |
} | |
return inputStream; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment