private void executeScriptGetFileRequest ( String openCpuSessionKey , String scriptOutputFilename , String outputPathname ) throws IOException { URI scriptGetValueResponseUri = getScriptGetFileResponseUri ( openCpuSessionKey , scriptOutputFilename ) ; HttpGet httpGet = new HttpGet ( scriptGetValueResponseUri ) ; try ( CloseableHttpResponse response = httpClient . execute ( httpGet ) ) { int statusCode = response . getStatusLine ( ) . getStatusCode ( ) ; if ( statusCode >= 200 && statusCode < 300 ) { HttpEntity entity = response . getEntity ( ) ; Files . copy ( entity . getContent ( ) , Paths . get ( outputPathname ) ) ; EntityUtils . consume ( entity ) ; } else { throw new ClientProtocolException ( format ( FORMAT_UNEXPECTED_RESPONSE_STATUS , statusCode ) ) ; } } }
Retrieve R script file response using OpenCPU and write to file