List of usage examples for org.apache.commons.io FileUtils forceDeleteOnExit
public static void forceDeleteOnExit(File file) throws IOException
From source file:com.c4om.autoconf.ulysses.configanalyzer.guilauncher.ChromeAppEditorGUILauncher.java
/** * @see com.c4om.autoconf.ulysses.interfaces.configanalyzer.core.GUILauncher#launchGUI(com.c4om.autoconf.ulysses.interfaces.configanalyzer.core.datastructures.ConfigurationAnalysisContext, com.c4om.autoconf.ulysses.interfaces.Target) *///from w ww. j av a 2 s . com @SuppressWarnings("resource") @Override public void launchGUI(ConfigurationAnalysisContext context, Target target) throws GUILaunchException { try { List<File> temporaryFolders = this.getTemporaryStoredChangesetsAndConfigs(context, target); for (File temporaryFolder : temporaryFolders) { //The temporary folder where one subfolder per analyzer execution will be stored (and removed). File temporaryFolderRoot = temporaryFolder.getParentFile().getParentFile(); System.out.println("Writing launch properties."); //Now, we build the properties file Properties launchProperties = new Properties(); String relativeTemporaryFolder = temporaryFolder.getAbsolutePath() .replaceAll("^" + Pattern.quote(temporaryFolderRoot.getAbsolutePath()), "") .replaceAll("^" + Pattern.quote(File.separator), "") .replaceAll(Pattern.quote(File.separator) + "$", "") .replaceAll(Pattern.quote(File.separator) + "+", "/"); // launchProperties.put(KEY_LOAD_RECOMMENDATIONS_FILE, relativeTemporaryFolder+CHANGESET_TO_APPLY); launchProperties.put(KEY_CATALOG, relativeTemporaryFolder + CATALOG_FILE_PATH); Writer writer = new OutputStreamWriter( new FileOutputStream(new File(temporaryFolderRoot, LAUNCH_PROPERTIES_FILE_NAME)), Charsets.UTF_8); launchProperties.store(writer, ""); writer.close(); System.out.println("Launch properties written!!!!"); System.out.println("Launching XML editor Chrome app"); Properties configurationAnalyzerProperties = context.getConfigurationAnalyzerSettings(); String chromeLocation = configurationAnalyzerProperties.getProperty(PROPERTIES_KEY_CHROME_LOCATION); String editorChromeAppLocation = configurationAnalyzerProperties .getProperty(PROPERTIES_KEY_EDITOR_CHROME_APP_LOCATION); ProcessBuilder chromeEditorPB = new ProcessBuilder( ImmutableList.of(chromeLocation, "--load-and-launch-app=" + editorChromeAppLocation)); chromeEditorPB.directory(new File(editorChromeAppLocation)); chromeEditorPB.start(); System.out.println("Editor started!!!"); System.out.println("Now, make all your changes and press ENTER when finished..."); new Scanner(System.in).nextLine(); FileUtils.forceDeleteOnExit(temporaryFolder.getParentFile()); } } catch (IOException e) { throw new GUILaunchException(e); } }
From source file:com.ewcms.content.resource.service.ResourceService.java
@Override public Resource update(Integer id, File file, String path, Resource.Type type) throws IOException { Resource resource = resourceDao.get(id); Assert.notNull(resource, "Resourc is not exist,id = " + id); FileUtils.copyFile(file, new File(resource.getPath())); if (type == Resource.Type.IMAGE) { if (resource.getPath().equals(resource.getThumbPath())) { String thumbUri = getThumbUri(resource.getUri()); String thumbPath = Resource.resourcePath(resource.getSite(), thumbUri); if (ImageUtil.compression(file.getPath(), thumbPath, 128, 128)) { resource.setThumbUri(thumbUri); }//w ww .j av a 2 s.c o m } else { if (!ImageUtil.compression(file.getPath(), resource.getThumbPath(), 128, 128)) { FileUtils.forceDeleteOnExit(new File(resource.getThumbPath())); resource.setThumbUri(resource.getUri()); } } } resource.setStatus(Status.NORMAL); resource.setUpdateTime(new Date(System.currentTimeMillis())); resource.setName(getFilename(path)); resourceDao.persist(resource); return resource; }
From source file:atg.tools.dynunit.test.util.FileUtil.java
/** * @see org.apache.commons.io.FileUtils#forceDeleteOnExit(java.io.File) *//*from w w w. j a v a2s . c om*/ @Deprecated public static void deleteDirectoryOnShutdown(@NotNull final File tmpDir) { try { FileUtils.forceDeleteOnExit(tmpDir); } catch (IOException e) { logger.catching(Level.ERROR, e); } }
From source file:gov.nih.nci.firebird.service.protocol.ImportTestFileHelper.java
public File getCopy(ImportTestFile testFile) { File temporaryCopy = null;// w ww.ja v a 2 s.c o m try { String fileName = getFileName(testFile); temporaryCopy = File.createTempFile(fileName, ""); FileUtils.forceDeleteOnExit(temporaryCopy); FileUtils.copyInputStreamToFile(ImportTestFileHelper.class.getResourceAsStream(fileName), temporaryCopy); } catch (IOException e) { Assert.fail(e.getMessage()); } return temporaryCopy; }
From source file:com.joyent.manta.client.MantaClientAuthenticationChangeIT.java
private static void swapKeyLocation(final AuthAwareConfigContext config, final boolean fromPathToContent) throws IOException { if (fromPathToContent) { // move key to MANTA_KEY_CONTENT final String keyContent = FileUtils.readFileToString(new File(config.getMantaKeyPath()), StandardCharsets.UTF_8); config.setMantaKeyPath(null);/*from www. ja v a 2s . co m*/ config.setPrivateKeyContent(keyContent); return; } // move key to MANTA_KEY_FILE final Path tempKey = Paths.get("/Users/tomascelaya/sandbox/"); FileUtils.forceDeleteOnExit(tempKey.toFile()); FileUtils.writeStringToFile(tempKey.toFile(), config.getPrivateKeyContent(), StandardCharsets.UTF_8); config.setPrivateKeyContent(null); config.setMantaKeyPath(tempKey.toString()); }
From source file:edu.cornell.med.icb.goby.algorithmic.algorithm.TestAccumulate.java
@AfterClass public static void cleanupTestDirectory() throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Deleting base test directory: " + BASE_TEST_DIR); }/*from w ww .ja v a 2 s . c o m*/ FileUtils.forceDeleteOnExit(new File(BASE_TEST_DIR)); }
From source file:com.iyonger.apm.web.configuration.Config.java
/** * Resolve nGrinder home path./*from w w w. j ava 2s . c o m*/ * * @return resolved home */ protected Home resolveHome() { if (StringUtils.isNotBlank(System.getProperty("unit-test"))) { final String tempDir = System.getProperty("java.io.tmpdir"); final File tmpHome = new File(tempDir, ".ngrinder"); if (tmpHome.mkdirs()) { LOG.info("{} is created", tmpHome.getPath()); } try { FileUtils.forceDeleteOnExit(tmpHome); } catch (IOException e) { LOG.error("Error while setting forceDeleteOnExit on {}", tmpHome); } return new Home(tmpHome); } String userHomeFromEnv = System.getenv("NGRINDER_HOME"); String userHomeFromProperty = System.getProperty("ngrinder.home"); if (!StringUtils.equals(userHomeFromEnv, userHomeFromProperty)) { CoreLogger.LOGGER.warn("The path to ngrinder-home is ambiguous:"); CoreLogger.LOGGER.warn(" System Environment: NGRINDER_HOME=" + userHomeFromEnv); CoreLogger.LOGGER.warn(" Java System Property: ngrinder.home=" + userHomeFromProperty); CoreLogger.LOGGER.warn(" '" + userHomeFromProperty + "' is accepted."); } String userHome = StringUtils.defaultIfEmpty(userHomeFromProperty, userHomeFromEnv); if (StringUtils.isEmpty(userHome)) { userHome = System.getProperty("user.home") + File.separator + NGRINDER_DEFAULT_FOLDER; } else if (StringUtils.startsWith(userHome, "~" + File.separator)) { userHome = System.getProperty("user.home") + File.separator + userHome.substring(2); } else if (StringUtils.startsWith(userHome, "." + File.separator)) { userHome = System.getProperty("user.dir") + File.separator + userHome.substring(2); } userHome = FilenameUtils.normalize(userHome); File homeDirectory = new File(userHome); CoreLogger.LOGGER.info("nGrinder home directory:{}.", homeDirectory.getPath()); return new Home(homeDirectory); }
From source file:gov.nih.nci.firebird.commons.selenium2.util.FileDownloadUtils.java
private static File getDestinationFile() throws IOException { File file = File.createTempFile("download", null); FileUtils.forceDeleteOnExit(file); return file;//from w w w. ja v a 2 s . com }
From source file:com.joyent.manta.client.crypto.EncryptingEntityTest.java
private static void verifyEncryptionWorksRoundTrip(byte[] keyBytes, SupportedCipherDetails cipherDetails, HttpEntity entity, Predicate<byte[]> validator) throws Exception { SecretKey key = SecretKeyUtils.loadKey(keyBytes, cipherDetails); EncryptingEntity encryptingEntity = new EncryptingEntity(key, cipherDetails, entity); File file = File.createTempFile("ciphertext-", ".data"); FileUtils.forceDeleteOnExit(file); try (FileOutputStream out = new FileOutputStream(file)) { encryptingEntity.writeTo(out);/*from ww w .ja v a2 s. c om*/ } Assert.assertEquals(file.length(), encryptingEntity.getContentLength(), "Expected ciphertext file size doesn't match actual file size " + "[originalContentLength=" + entity.getContentLength() + "] -"); byte[] iv = encryptingEntity.getCipher().getIV(); Cipher cipher = cipherDetails.getCipher(); cipher.init(Cipher.DECRYPT_MODE, key, cipherDetails.getEncryptionParameterSpec(iv)); final long ciphertextSize; if (cipherDetails.isAEADCipher()) { ciphertextSize = encryptingEntity.getContentLength(); } else { ciphertextSize = encryptingEntity.getContentLength() - cipherDetails.getAuthenticationTagOrHmacLengthInBytes(); } try (FileInputStream in = new FileInputStream(file); BoundedInputStream bin = new BoundedInputStream(in, ciphertextSize); CipherInputStream cin = new CipherInputStream(bin, cipher)) { final byte[] actualBytes = IOUtils.toByteArray(cin); final byte[] hmacBytes = new byte[cipherDetails.getAuthenticationTagOrHmacLengthInBytes()]; in.read(hmacBytes); Assert.assertTrue(validator.test(actualBytes), "Entity validation failed"); } }
From source file:com.joyent.manta.client.MantaClientPutIT.java
@Test public final void testPutWithPlainTextFileUTF8RomanCharacters() throws IOException { final String name = UUID.randomUUID().toString(); final String path = testPathPrefix + name; File temp = File.createTempFile("upload", ".txt"); FileUtils.forceDeleteOnExit(temp); Files.write(temp.toPath(), TEST_DATA.getBytes(StandardCharsets.UTF_8)); MantaObject response = mantaClient.put(path, temp); String contentType = response.getContentType(); Assert.assertEquals(contentType, "text/plain", "Content type wasn't detected correctly"); String actual = mantaClient.getAsString(path); Assert.assertEquals(actual, TEST_DATA, "Uploaded file didn't match expectation"); }