code: private void streamToOutput(InputStream inputStream) throws IOException {
      try {
        byte[] buffer = new byte[4096];
        int bytesRead = -1;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
          outputStream.write(buffer, 0, bytesRead);
        }
        outputStream.flush();
      } finally {
        inputStream.close();
      }
    }
docs: Utility method to read all the bytes from an InputStream into the outputStream.
  @param inputStream   Stream of bytes to read from.
  @throws IOException  Thrown on errors reading / writing.