@ SuppressWarnings ( "deprecation" ) public static InputStream fetchFile ( final URI uri , final ClientConfiguration config ) throws IOException { HttpParams httpClientParams = new BasicHttpParams ( ) ; HttpProtocolParams . setUserAgent ( httpClientParams , getUserAgent ( config , null ) ) ; HttpConnectionParams . setConnectionTimeout ( httpClientParams , getConnectionTimeout ( config ) ) ; HttpConnectionParams . setSoTimeout ( httpClientParams , getSocketTimeout ( config ) ) ; DefaultHttpClient httpclient = new DefaultHttpClient ( httpClientParams ) ; if ( config != null ) { String proxyHost = config . getProxyHost ( ) ; int proxyPort = config . getProxyPort ( ) ; if ( proxyHost != null && proxyPort > 0 ) { HttpHost proxy = new HttpHost ( proxyHost , proxyPort ) ; httpclient . getParams ( ) . setParameter ( ConnRoutePNames . DEFAULT_PROXY , proxy ) ; if ( config . getProxyUsername ( ) != null && config . getProxyPassword ( ) != null ) { httpclient . getCredentialsProvider ( ) . setCredentials ( new AuthScope ( proxyHost , proxyPort ) , new NTCredentials ( config . getProxyUsername ( ) , config . getProxyPassword ( ) , config . getProxyWorkstation ( ) , config . getProxyDomain ( ) ) ) ; } } } HttpResponse response = httpclient . execute ( new HttpGet ( uri ) ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) != 200 ) { throw new IOException ( "Error fetching file from " + uri + ": " + response ) ; } return new HttpClientWrappingInputStream ( httpclient , response . getEntity ( ) . getContent ( ) ) ; }
Fetches a file from the URI given and returns an input stream to it .