Here you can find the source of getInputStream(URLConnection connection)
Parameter | Description |
---|---|
connection | connection which supplies the stream |
public static InputStream getInputStream(URLConnection connection) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.net.URLConnection; import java.util.zip.GZIPInputStream; import java.util.zip.InflaterInputStream; public class Main { /**// w ww. java2 s . co m * gets the input stream from an url connection * @param connection connection which supplies the stream * @return connection.getInputStream() which may be wrapped in a decoder */ public static InputStream getInputStream(URLConnection connection) throws IOException { InputStream in = connection.getInputStream(); String encoding = connection.getContentEncoding(); if (encoding != null) { if (encoding.equals("deflate")) return new InflaterInputStream(in); else if (encoding.equals("gzip")) return new GZIPInputStream(in); else throw new IOException("unexpected encoding: " + encoding); } return in; } }