private static File createFileInTmp(String prefix, String suffix,
      String reason, boolean isDirectory) throws IOException {
    File file = File.createTempFile(prefix, suffix);
    if (isDirectory && (!file.delete() || !file.mkdirs())) {
      // TODO: or we could just generate a name ourselves and not do this?
      throw new IOException("Cannot recreate " + file + " as directory");
    }
    file.deleteOnExit();
    LOG.info(reason + "; created a tmp file: " + file.getAbsolutePath());
    return file;
  }
create temporary file and register it to delete-on-exit hook.
File.deleteOnExit is not used for possible memory leakage.

Make sure to use {@link #deleteTmpFile(File)} after the file is no longer required,
and has been deleted to avoid a memory leak.
common/src/java/org/apache/hadoop/hive/common/FileUtils.java