/** * 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; } }
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); } } }
File file = files[i]; try { forceDeleteOnExit(file); } catch (IOException ioe) { exception = ioe;
@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) }
@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(); } }
@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")), ""); }
@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)); }
@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);; }
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");
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");
@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; } }
public void teardown() throws Exception { if (bkStartupThread != null) { bkStartupThread.interrupt(); bkStartupThread.join(); } for (File dir : tmpDirs) { FileUtils.forceDeleteOnExit(dir); } }
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..."); } }
/** * 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); } }
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; }
@Override public void tearDown() throws Exception { LOGGER.info("Shutting down Kafka Server..."); kafkaServer.shutdown(); kafkaServer = null; FileUtils.forceDeleteOnExit(KafkaTestUtils.DEFAULT_LOG_DIR); }
public static void forceDeleteOnExit(ActionContext actionContext) throws IOException{ Thing self = actionContext.getObject("self"); File file = getFile(self, "getFile", actionContext); FileUtils.forceDeleteOnExit(file); }
/** * 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()); }
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; }
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(); } }