code: 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));
        }
      }
    }
docs: Retrieve R script file response using OpenCPU and write to file
  
  @param openCpuSessionKey OpenCPU session key
  @param scriptOutputFilename R script output filename
  @param outputPathname Output pathname
  @throws IOException if error occured during script response retrieval