code: private void streamAndMove(InputStream is, File destFile) throws IOException {
          if (!tempAndMove) {
              stream(is, destFile);
          } else {
              //create parent directory
              downloadTaskDir.mkdirs();
  
              //create name of temporary file
              File tempFile = File.createTempFile(destFile.getName(), ".part",
                      this.downloadTaskDir);
  
              //stream and move
              stream(is, tempFile);
              if (destFile.exists()) {
                  //Delete destFile if it exists before renaming tempFile.
                  //Otherwise renaming might fail.
                  if (!destFile.delete()) {
                      throw new IOException("Could not delete old destination file '" +
                              destFile.getAbsolutePath() + "'.");
                  }
              }
              if (!tempFile.renameTo(destFile)) {
                  throw new IOException("Failed to move temporary file '" +
                          tempFile.getAbsolutePath() + "' to destination file '" +
                          destFile.getAbsolutePath() + "'.");
              }
          }
      }
docs: If {@link #tempAndMove} is <code>true</code>, copy bytes from an input
  stream to a temporary file and log progress. Upon successful
  completion, move the temporary file to the given destination. If
  {@link #tempAndMove} is <code>false</code>, just forward to
  {@link #stream(InputStream, File)}.
  @param is the input stream to read
  @param destFile the destination file
  @throws IOException if an I/O error occurs