code: public String getUniqueFilename(String baseFileName, String extension, boolean cleanBaseFileName, String... ancestorFolders)
      {
          if (cleanBaseFileName)
          {
              baseFileName = PathUtil.cleanFileName(baseFileName);
          }
  
          if (ancestorFolders != null)
          {
              Path pathToFile = Paths.get("", Stream.of(ancestorFolders).map(ancestor -> PathUtil.cleanFileName(ancestor)).toArray(String[]::new)).resolve(baseFileName);
              baseFileName = pathToFile.toString();
          }
          String filename = baseFileName + "." + extension;
  
          // FIXME this looks nasty
          while (usedFilenames.contains(filename))
          {
              filename = baseFileName + "." + index.getAndIncrement() + "." + extension;
          }
          usedFilenames.add(filename);
  
          return filename;
      }
docs: Returns a unique file name
  @param baseFileName the requested base name for the file
  @param extension the requested extension for the file
  @param cleanBaseFileName specify if the <code>baseFileName</code> has to be cleaned before being used (i.e. 'jboss-web' should not be cleaned to avoid '-' to become '_')
  @param ancestorFolders specify the ancestor folders for the file (if there's no ancestor folder, just pass 'null' value)
  @return a String representing the unique file generated