code: public static long copyToFileAndClose(InputStream is, File file) throws IOException
    {
      file.getParentFile().mkdirs();
      try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
        final long result = ByteStreams.copy(is, os);
        // Workarround for http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/759aa847dcaf
        os.flush();
        return result;
      }
      finally {
        is.close();
      }
    }
docs: Copy from an input stream to a file (and buffer it) and close the input stream.
  <p>
  It is highly recommended to use FileUtils.retryCopy whenever possible, and not use a raw `InputStream`
  
  @param is   The input stream to copy bytes from. `is` is closed regardless of the copy result.
  @param file The file to copy bytes to. Any parent directories are automatically created.
  
  @return The count of bytes written to the file
  
  @throws IOException