org.apache.nifi.util.file.FileUtils.deleteFilesInDir()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中org.apache.nifi.util.file.FileUtils.deleteFilesInDir()方法的一些代码示例,展示了FileUtils.deleteFilesInDir()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.deleteFilesInDir()方法的具体详情如下:
包路径:org.apache.nifi.util.file.FileUtils
类名称:FileUtils
方法名:deleteFilesInDir

FileUtils.deleteFilesInDir介绍

[英]Deletes all files (not directories..) in the given directory (non recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
[中]删除所有文件(不是目录..)在与给定文件名筛选器匹配的给定目录(非递归)中。如果无法删除任何文件,则会在警告时将其打印到给定记录器。

代码示例

代码示例来源:origin: apache/nifi

/**
 * Deletes all files (not directories..) in the given directory (non recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given
 * logger.
 *
 * @param directory the directory to scan for files to delete
 * @param filter if null then no filter is used
 * @param logger the logger to use
 */
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger) {
  FileUtils.deleteFilesInDir(directory, filter, logger, false);
}

代码示例来源:origin: apache/nifi

/**
 * Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
 *
 * @param directory the directory to scan
 * @param filter if null then no filter is used
 * @param logger the logger to use
 * @param recurse indicates whether to recurse subdirectories
 */
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse) {
  FileUtils.deleteFilesInDir(directory, filter, logger, recurse, false);
}

代码示例来源:origin: apache/nifi

/**
 * Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
 *
 * @param directory the directory to scan
 * @param filter if null then no filter is used
 * @param logger the logger
 * @param recurse whether to recurse subdirectories or not
 * @param deleteEmptyDirectories default is false; if true will delete directories found that are empty
 */
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse, final boolean deleteEmptyDirectories) {
  // ensure the specified directory is actually a directory and that it exists
  if (null != directory && directory.isDirectory()) {
    final File ingestFiles[] = directory.listFiles();
    for (File ingestFile : ingestFiles) {
      boolean process = (filter == null) ? true : filter.accept(directory, ingestFile.getName());
      if (ingestFile.isFile() && process) {
        FileUtils.deleteFile(ingestFile, logger, 3);
      }
      if (ingestFile.isDirectory() && recurse) {
        FileUtils.deleteFilesInDir(ingestFile, filter, logger, recurse, deleteEmptyDirectories);
        if (deleteEmptyDirectories && ingestFile.list().length == 0) {
          FileUtils.deleteFile(ingestFile, logger, 3);
        }
      }
    }
  }
}

代码示例来源:origin: apache/nifi

@Override
public void purge() {
  // delete all content from repositories
  for (final Path path : containers.values()) {
    FileUtils.deleteFilesInDir(path.toFile(), null, LOG, true);
  }
  for (final Path path : containers.values()) {
    if (!Files.exists(path)) {
      throw new RepositoryPurgeException("File " + path.toFile().getAbsolutePath() + " does not exist");
    }
    // Try up to 10 times to see if the directory is writable, in case another process (like a
    // virus scanner) has the directory temporarily locked
    boolean writable = false;
    for (int i = 0; i < 10; i++) {
      if (Files.isWritable(path)) {
        writable = true;
        break;
      } else {
        try {
          Thread.sleep(100L);
        } catch (final Exception e) {
        }
      }
    }
    if (!writable) {
      throw new RepositoryPurgeException("File " + path.toFile().getAbsolutePath() + " is not writable");
    }
  }
  resourceClaimManager.purge();
}

代码示例来源:origin: org.apache.nifi/nifi-utils

/**
 * Deletes all files (not directories..) in the given directory (non recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given
 * logger.
 *
 * @param directory the directory to scan for files to delete
 * @param filter if null then no filter is used
 * @param logger the logger to use
 */
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger) {
  FileUtils.deleteFilesInDir(directory, filter, logger, false);
}

代码示例来源:origin: org.apache.nifi/nifi-utils

/**
 * Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
 *
 * @param directory the directory to scan
 * @param filter if null then no filter is used
 * @param logger the logger to use
 * @param recurse indicates whether to recurse subdirectories
 */
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse) {
  FileUtils.deleteFilesInDir(directory, filter, logger, recurse, false);
}

代码示例来源:origin: org.apache.nifi/nifi-utils

/**
 * Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
 *
 * @param directory the directory to scan
 * @param filter if null then no filter is used
 * @param logger the logger
 * @param recurse whether to recurse subdirectories or not
 * @param deleteEmptyDirectories default is false; if true will delete directories found that are empty
 */
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse, final boolean deleteEmptyDirectories) {
  // ensure the specified directory is actually a directory and that it exists
  if (null != directory && directory.isDirectory()) {
    final File ingestFiles[] = directory.listFiles();
    for (File ingestFile : ingestFiles) {
      boolean process = (filter == null) ? true : filter.accept(directory, ingestFile.getName());
      if (ingestFile.isFile() && process) {
        FileUtils.deleteFile(ingestFile, logger, 3);
      }
      if (ingestFile.isDirectory() && recurse) {
        FileUtils.deleteFilesInDir(ingestFile, filter, logger, recurse, deleteEmptyDirectories);
        if (deleteEmptyDirectories && ingestFile.list().length == 0) {
          FileUtils.deleteFile(ingestFile, logger, 3);
        }
      }
    }
  }
}

相关文章