code: private File createNewUniqueFile(File srcFile) throws IOException {
          String dateString = getDateString();
          int index = findFileIndexAndUpdateCounter(dateString);
  
          String destFileName;
          File destFile;
          do {
              int counter = lastCounter++;
              destFileName = fileName + dateString + '.' + counter + fileExtension;
              destFile = new File(directory, destFileName);
  
              boolean success;
              if (srcFile == null) {
                  success = destFile.createNewFile();
              } else {
                  // We don't want to rename over an existing file, so try to
                  // avoid doing so with a racy exists() check.
                  if (!destFile.exists()) {
                      success = srcFile.renameTo(destFile);
                  } else {
                      success = false;
                  }
              }
  
              if (success) {
                  // Add the file to our list, which will cause old files to be
                  // deleted if we've reached the max.
                  addFile(index, destFileName);
                  return destFile;
              }
          } while (destFile.isFile());
  
          if (srcFile != null && copyFileTo(srcFile, destFile)) {
              addFile(index, destFileName);
              return FileLogUtils.deleteFile(srcFile) ? destFile : null;
          }
  
          Tr.error(tc, "UNABLE_TO_DELETE_RESOURCE_NOEX", new Object[] { destFile });
          return null;
      }
docs: Create a new unique file name. If the source file is specified, the new
  file should be created by renaming the source file as the unique file.
  
  @param srcFile the file to rename, or null to create a new file
  @return the newly created file, or null if the could not be created
  @throws IOException if an unexpected I/O error occurs