private HttpResponse executeCurrentRequest ( long currentRequestLastBytePos , GenericUrl requestUrl , HttpHeaders requestHeaders , OutputStream outputStream ) throws IOException { // prepare the GET request HttpRequest request = requestFactory . buildGetRequest ( requestUrl ) ; // add request headers if ( requestHeaders != null ) { request . getHeaders ( ) . putAll ( requestHeaders ) ; } // set Range header (if necessary) if ( bytesDownloaded != 0 || currentRequestLastBytePos != - 1 ) { StringBuilder rangeHeader = new StringBuilder ( ) ; rangeHeader . append ( "bytes=" ) . append ( bytesDownloaded ) . append ( "-" ) ; if ( currentRequestLastBytePos != - 1 ) { rangeHeader . append ( currentRequestLastBytePos ) ; } request . getHeaders ( ) . setRange ( rangeHeader . toString ( ) ) ; } // execute the request and copy into the output stream HttpResponse response = request . execute ( ) ; try { ByteStreams . copy ( response . getContent ( ) , outputStream ) ; } finally { response . disconnect ( ) ; } return response ; }
Executes the current request .