@ Override public InputStream download ( String uri ) { HttpURLConnection connection = null ; String errorMsg ; try { URL url = new URI ( uri ) . toURL ( ) ; connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . setDoOutput ( false ) ; // Check the HTTP response code int responseCode = connection . getResponseCode ( ) ; if ( responseCode == HttpURLConnection . HTTP_OK ) { logger . debug ( "Download completed with HTTP response code: {}" , connection . getResponseCode ( ) ) ; return org . apache . commons . io . IOUtils . toBufferedInputStream ( connection . getInputStream ( ) ) ; } errorMsg = String . format ( "Unable to download. Response code: %d" , responseCode ) ; logger . error ( errorMsg ) ; throw new ConductorClientException ( errorMsg ) ; } catch ( URISyntaxException | MalformedURLException e ) { errorMsg = String . format ( "Invalid uri specified: %s" , uri ) ; logger . error ( errorMsg , e ) ; throw new ConductorClientException ( errorMsg , e ) ; } catch ( IOException e ) { errorMsg = String . format ( "Error downloading from uri: %s" , uri ) ; logger . error ( errorMsg , e ) ; throw new ConductorClientException ( errorMsg , e ) ; } finally { if ( connection != null ) { connection . disconnect ( ) ; } } }
Downloads the payload from the given uri .