org.apache.commons.io.FileUtils.forceDeleteOnExit()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(408)

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

FileUtils.forceDeleteOnExit介绍

[英]Schedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.
[中]计划在JVM退出时删除文件。如果文件是目录,则删除它和所有子目录。

代码示例

代码示例来源:origin: commons-io/commons-io

/**
 * Cleans a directory without deleting it.
 *
 * @param directory directory to clean, must not be {@code null}
 * @throws NullPointerException if the directory is {@code null}
 * @throws IOException          in case cleaning is unsuccessful
 */
private static void cleanDirectoryOnExit(final File directory) throws IOException {
  final File[] files = verifiedListFiles(directory);
  IOException exception = null;
  for (final File file : files) {
    try {
      forceDeleteOnExit(file);
    } catch (final IOException ioe) {
      exception = ioe;
    }
  }
  if (null != exception) {
    throw exception;
  }
}

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

private void initOperationLogRootDir() {
 operationLogRootDir = new File(
   hiveConf.getVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION));
 isOperationLogEnabled = true;
 if (operationLogRootDir.exists() && !operationLogRootDir.isDirectory()) {
  LOG.warn("The operation log root directory exists, but it is not a directory: " +
    operationLogRootDir.getAbsolutePath());
  isOperationLogEnabled = false;
 }
 if (!operationLogRootDir.exists()) {
  if (!operationLogRootDir.mkdirs()) {
   LOG.warn("Unable to create operation log root directory: " +
     operationLogRootDir.getAbsolutePath());
   isOperationLogEnabled = false;
  }
 }
 if (isOperationLogEnabled) {
  LOG.info("Operation log root directory is created: " + operationLogRootDir.getAbsolutePath());
  try {
   FileUtils.forceDeleteOnExit(operationLogRootDir);
  } catch (IOException e) {
   LOG.warn("Failed to schedule cleanup HS2 operation logging root dir: " +
     operationLogRootDir.getAbsolutePath(), e);
  }
 }
}

代码示例来源:origin: org.apache.commons/commons-io

File file = files[i];
try {
  forceDeleteOnExit(file);
} catch (IOException ioe) {
  exception = ioe;

代码示例来源:origin: commons-io/commons-io

@Test
public void testIO276() throws Exception {
  final File dir = new File("target", "IO276");
  assertTrue(dir + " should not be present", dir.mkdirs());
  final File file = new File(dir, "IO276.txt");
  assertTrue(file + " should not be present", file.createNewFile());
  FileUtils.forceDeleteOnExit(dir);
  // If this does not work, test will fail next time (assuming target is not cleaned)
}

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

@After
public void tearDown() throws IOException, SQLException {
 File metaStoreDir = new File(testMetastoreDB);
 if (metaStoreDir.exists()) {
  FileUtils.forceDeleteOnExit(metaStoreDir);
 }
 System.setOut(outStream);
 System.setErr(errStream);
 if (conn != null) {
  conn.close();
 }
}

代码示例来源:origin: apache/incubator-gobblin

@BeforeClass
public void setUp()
  throws IOException, URISyntaxException {
 // Creating userCustomized stuff
 this.jobConfigDir =
   Files.createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toFile();
 FileUtils.forceDeleteOnExit(this.jobConfigDir);
 //User specified file content:
 this.userProp = new Properties();
 userProp.setProperty("a", "1");
 userProp.setProperty("templated0", "2");
 userProp.setProperty("required0", "r0");
 userProp.setProperty("required1", "r1");
 userProp.setProperty("required2", "r2");
 userProp.setProperty("job.template", "templates/test.template");
 // User specified file's name : /[jobConfigDirName]/user.attr
 userProp.store(new FileWriter(new File(this.jobConfigDir, "user.attr")), "");
}

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

@Test
public void test() throws Exception {
  // String input =
  // "src/test/resources/data/base_cuboid,src/test/resources/data/6d_cuboid";
  String output = "target/test-output/merged_cuboid";
  String cubeName = "test_kylin_cube_with_slr_ready";
  String jobname = "merge_cuboid";
  File baseFolder = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "base");
  FileUtils.forceDelete(baseFolder);
  baseFolder.mkdir();
  FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), baseFolder);
  FileUtils.forceDeleteOnExit(baseFolder);
  File eightFoler = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "8d");
  FileUtils.forceDelete(eightFoler);
  eightFoler.mkdir();
  FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), eightFoler);
  FileUtils.forceDeleteOnExit(eightFoler);
  FileUtil.fullyDelete(new File(output));
  // CubeManager cubeManager =
  // CubeManager.getInstanceFromEnv(getTestConfig());
  String[] args = { "-input", baseFolder.getAbsolutePath() + "," + eightFoler.getAbsolutePath(), "-cubename", cubeName, "-segmentname", "20130331080000_20131212080000", "-output", output, "-jobname", jobname };
  assertEquals("Job failed", 0, ToolRunner.run(conf, new MergeCuboidJob(), args));
}

代码示例来源:origin: apache/incubator-gobblin

@BeforeClass
public void setUp() throws Exception {
 this.jobConfigDir =
   Files.createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName()))
     .toString();
 FileUtils.forceDeleteOnExit(new File(this.jobConfigDir));
 FileUtils.copyDirectory(new File(JOB_CONFIG_FILE_DIR), new File(jobConfigDir));
 Properties properties = new Properties();
 try (Reader schedulerPropsReader = new FileReader("gobblin-test/resource/gobblin.test.properties")) {
  properties.load(schedulerPropsReader);
 }
 properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, jobConfigDir);
 properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, jobConfigDir);
 properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, "1000");
 properties.setProperty(ConfigurationKeys.METRICS_ENABLED_KEY, "false");
 SchedulerService quartzService = new SchedulerService(new Properties());
 this.jobScheduler = new JobScheduler(properties, quartzService);
 this.serviceManager = new ServiceManager(Lists.newArrayList(quartzService, this.jobScheduler));
 this.serviceManager.startAsync().awaitHealthy(10, TimeUnit.SECONDS);;
}

代码示例来源:origin: apache/incubator-gobblin

this.jobConfigDir = java.nio.file.Files.createTempDirectory(
  String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toFile();
FileUtils.forceDeleteOnExit(this.jobConfigDir);
this.subDir1 = new File(this.jobConfigDir, "test1");
this.subDir11 = new File(this.subDir1, "test11");

代码示例来源:origin: apache/incubator-gobblin

this.jobConfigDir = java.nio.file.Files.createTempDirectory(
  String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toFile();
FileUtils.forceDeleteOnExit(this.jobConfigDir);
this.subDir1 = new File(this.jobConfigDir, "test1");
this.subDir11 = new File(this.subDir1, "test11");

代码示例来源:origin: naver/ngrinder

@Override
  protected AgentHome resolveHome() {
    AgentHome resolveHome = super.resolveHome();
    File directory = new File(resolveHome.getDirectory(), "tmp_" + String.valueOf(counter));
    resolveHome = new AgentHome(directory);
    try {
      FileUtils.forceDeleteOnExit(directory);
    } catch (IOException e) {
      noOp();
    }
    return resolveHome;
  }
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-core

public void teardown() throws Exception {
  if (bkStartupThread != null) {
    bkStartupThread.interrupt();
    bkStartupThread.join();
  }
  for (File dir : tmpDirs) {
    FileUtils.forceDeleteOnExit(dir);
  }
}

代码示例来源:origin: org.ops4j.pax.exam/pax-exam-container-karaf

private void forceCleanup() {
  LOGGER.info("Can't remove runtime system; shedule it for exit of the jvm.");
  try {
    FileUtils.forceDeleteOnExit(targetFolder);
  }
  catch (IOException e1) {
    LOGGER.error("Well, this should simply not happen...");
  }
}

代码示例来源:origin: org.wso2.carbon/org.wso2.carbon.container

/**
 * Force cleanup directories if required.
 */
private void forceCleanup() {
  try {
    FileUtils.forceDeleteOnExit(targetDirectory.toFile());
  } catch (IOException e) {
    logger.error("Error occured when deleting the Directory.", e);
  }
}

代码示例来源:origin: shilad/wikibrain

public static DataSource getDataSource() throws ClassNotFoundException, IOException, DaoException {
  Class.forName("org.h2.Driver");
  File tmpDir = File.createTempFile("wikibrain-h2", null);
  tmpDir.delete();
  tmpDir.mkdirs();
  DataSource ds = getDataSource(tmpDir);
  FileUtils.forceDeleteOnExit(tmpDir);
  return ds;
}

代码示例来源:origin: locationtech/geowave

@Override
public void tearDown() throws Exception {
 LOGGER.info("Shutting down Kafka Server...");
 kafkaServer.shutdown();
 kafkaServer = null;
 FileUtils.forceDeleteOnExit(KafkaTestUtils.DEFAULT_LOG_DIR);
}

代码示例来源:origin: org.xworker/xworker_core

public static void forceDeleteOnExit(ActionContext actionContext) throws IOException{
  Thing self = actionContext.getObject("self");
  File file = getFile(self, "getFile", actionContext);
  
  FileUtils.forceDeleteOnExit(file);
}

代码示例来源:origin: omegat-org/omegat

/**
 * Init the preferences system using a temp dir for the config dir where
 * prefs files are read and written. Convenience method for
 * {@link #init(String)}.
 *
 * @throws IOException
 */
public static void init() throws IOException {
  Path tmp = Files.createTempDirectory("omegat");
  init(tmp.toString());
  FileUtils.forceDeleteOnExit(tmp.toFile());
}

代码示例来源:origin: epam/NGB

protected File getResourceFileCopy(String resourcePath) throws IOException {
  Resource resource = context.getResource(resourcePath);
  final File tmp = new File(fileManager.getTempDir(), resource.getFilename());
  FileUtils.copyFile(resource.getFile(), tmp);
  FileUtils.forceDeleteOnExit(tmp);
  return tmp;
}

代码示例来源:origin: CognitiveJ/cognitivej

public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(FILE_LOCATION_OF_US_PRESIDENT), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    imageOverlayBuilder.outlineFaceOnImage(faceScenarios.findSingleFace(imageFile), RectangleType.FULL).launchViewer();
  }
}

相关文章

FileUtils类方法