List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:net.lmxm.ute.executers.tasks.FileSystemDeleteTaskExecuterTest.java
/** * Test delete files single file./*from ww w.j a v a 2s . c om*/ */ @Test public void testDeleteFilesSingleFile() { try { final File file = File.createTempFile("UTE", ".TEST"); file.deleteOnExit(); FileUtils.touch(file); assertTrue(file.exists()); executer.deleteFiles(file.getAbsolutePath(), null, STOP_ON_ERROR); assertFalse(file.exists()); } catch (final IOException e) { fail(); } }
From source file:be.fedict.hsm.model.KeyStoreLoaderBean.java
private Map<String, PrivateKeyEntry> loadPKCS11(KeyStoreEntity keyStoreEntity) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableEntryException { File tmpConfigFile = File.createTempFile("pkcs11-", ".conf"); tmpConfigFile.deleteOnExit(); PrintWriter configWriter = new PrintWriter(new FileOutputStream(tmpConfigFile)); configWriter.println("name=HSM-" + keyStoreEntity.getId()); String path = keyStoreEntity.getPath(); LOG.debug("PKCS11 path: " + path); LOG.debug("slot list index: " + keyStoreEntity.getSlotListIndex()); configWriter.println("library=" + path); configWriter.println("slotListIndex=" + keyStoreEntity.getSlotListIndex()); configWriter.close();/*from w w w . j a v a 2 s. c om*/ SunPKCS11 sunPKCS11 = new SunPKCS11(tmpConfigFile.getAbsolutePath()); LOG.debug("adding SunPKCS11 JCA provider: " + sunPKCS11.getName()); /* * Reloads also need to work properly. */ Security.removeProvider(sunPKCS11.getName()); Security.addProvider(sunPKCS11); KeyStore keyStore = KeyStore.getInstance("PKCS11", sunPKCS11); if (null != keyStoreEntity.getPassword()) { keyStore.load(null, keyStoreEntity.getPassword().toCharArray()); } else { keyStore.load(null, null); } String keyStorePassword = keyStoreEntity.getPassword(); return loadKeys(keyStoreEntity, keyStore, keyStorePassword); }
From source file:net.hillsdon.reviki.wiki.plugin.PluginsImpl.java
private void updatePlugin(final ChangeInfo change) throws PageStoreException, IOException { final String name = change.getName(); final long revision = change.getRevision(); if (change.isDeletion()) { LOG.info("Removing " + name + " due to revision " + revision); _plugin.put(name, new PluginAtRevision(null, revision)); } else {/*from w w w . j a v a 2 s . c o m*/ LOG.info("Updating " + name + " to revision " + revision); final File jar = File.createTempFile("cached-", name); jar.deleteOnExit(); final OutputStream stream = new FileOutputStream(jar); try { _store.attachment(CONFIG_PLUGINS, name, revision, new ContentTypedSink() { public void setContentType(final String contentType) { } public void setFileName(final String attachment) { } public OutputStream stream() throws IOException { return stream; } }); } finally { IOUtils.closeQuietly(stream); } URL url = jar.toURI().toURL(); try { _plugin.put(name, new PluginAtRevision(new Plugin(name, url, _context), revision)); } catch (InvalidPluginException ex) { // Some way to indicate the error to the user would be nice... _plugin.remove(name); LOG.error("Invalid plugin uploaded.", ex); } } }
From source file:com.playonlinux.core.python.PythonInstallerTest.java
@Test public void testPythonInstaller_DefineLogContextWithMethod_ContextIsSet() throws IOException, PlayOnLinuxException { File temporaryScript = File.createTempFile("testDefineLogContext", "py"); temporaryScript.deleteOnExit(); try (FileOutputStream fileOutputStream = new FileOutputStream(temporaryScript)) { fileOutputStream.write(/*from w ww . j a v a 2 s . c o m*/ ("#!/usr/bin/env/python\n" + "from com.playonlinux.framework.templates import Installer\n" + "\n" + "class PlayOnLinuxBashInterpreter(Installer):\n" + " def main(self):\n" + " pass\n" + " def title(self):\n" + " return \"Mock Log Context\"\n").getBytes()); } PythonInterpreter interpreter = defaultJythonInterpreterFactory.createInstance(); interpreter.execfile(temporaryScript.getAbsolutePath()); PythonInstaller<ScriptTemplate> pythonInstaller = new PythonInstaller<>(interpreter, ScriptTemplate.class); assertEquals("Mock Log Context", pythonInstaller.extractLogContext()); }
From source file:com.playonlinux.python.PythonInstallerTest.java
@Test public void testPythonInstaller_DefineVariableAttributes_AttributesAreSet() throws IOException, ScriptFailureException { File temporaryOutput = new File("/tmp/testPythonInstaller_DefineVariableAttributes.log"); temporaryOutput.deleteOnExit(); if (temporaryOutput.exists()) { temporaryOutput.delete();//from w ww . j av a 2s .c o m } File temporaryScript = File.createTempFile("defineVariableAttributes", "py"); FileOutputStream fileOutputStream = new FileOutputStream(temporaryScript); fileOutputStream.write(("from com.playonlinux.framework.templates import MockWineSteamInstaller\n" + "\n" + "class Example(MockWineSteamInstaller):\n" + " logContext = \"testPythonInstaller_DefineVariableAttributes\"\n" + " title = \"Example with Steam\"\n" + " prefix = \"Prefix\"\n" + " wineversion = \"1.7.34\"\n" + " steamId = 130\n" + " packages = [\"package1\", \"package2\"]\n").getBytes()); Interpreter interpreter = Interpreter.createInstance(); interpreter.execfile(temporaryScript.getAbsolutePath()); PythonInstaller<ScriptTemplate> pythonInstaller = new PythonInstaller<>(interpreter, ScriptTemplate.class); pythonInstaller.exec(); assertEquals( "Implementation has to be done, but we have access to prefix (Prefix), " + "wineversion (1.7.34), steamId (130) and packages (['package1', 'package2'])." + " First package (to check that we have a list: package1\n", FileUtils.readFileToString(temporaryOutput)); }
From source file:eg.nileu.cis.nilestore.webapp.servlets.UploadServletRequest.java
/** * Init_ajax upload.//from www . j a v a2 s .c om * * @throws Exception * the exception */ @SuppressWarnings("unchecked") private void init_ajaxUpload() throws Exception { ServletFileUpload uploadHandler = new ServletFileUpload(new DiskFileItemFactory()); List<FileItem> items = uploadHandler.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { File f = File.createTempFile("upfile", ".tmp"); f.deleteOnExit(); item.write(f); fileName = item.getName(); if (fileName.contains(File.separator)) { fileName = fileName.substring(fileName.lastIndexOf(File.separator) + 1); } filePath = f.getAbsolutePath(); isFileFound = true; // Here we handle only one file at once break; } else { if (item.getFieldName().equals(DEST_FIELD_NAME)) { dest = Integer.valueOf(item.getString()); } } } String t = getParameter("t"); if (t != null) { returnType = t; } }
From source file:io.druid.emitter.graphite.WhiteListBasedConverterTest.java
@Test public void testWhiteListedStringArrayDimension() throws IOException { File mapFile = File.createTempFile("testing-" + System.nanoTime(), ".json"); mapFile.deleteOnExit(); try (OutputStream outputStream = new FileOutputStream(mapFile)) { IOUtils.copyLarge(getClass().getResourceAsStream("/testWhiteListedStringArrayDimension.json"), outputStream);//from www .j a va2s. com } WhiteListBasedConverter converter = new WhiteListBasedConverter(prefix, false, false, false, mapFile.getAbsolutePath(), new DefaultObjectMapper()); ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }) .build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname); GraphiteEvent graphiteEvent = converter.druidEventToGraphite(event); Assert.assertNotNull(graphiteEvent); Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", graphiteEvent.getEventPath()); }
From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java
public static File compressFile(final String projectName, final Path pathToCompress, final CompressionType compressionType, final BuildListener listener) throws IOException { File compressedArtifacts = null; try {//from w w w. j a v a 2 s . c om switch (compressionType) { case Zip: compressedArtifacts = File.createTempFile(projectName + "-", ".zip"); compressZipFile(compressedArtifacts, pathToCompress, listener); break; case Tar: compressedArtifacts = File.createTempFile(projectName + "-", ".tar"); compressTarFile(compressedArtifacts, pathToCompress, listener); break; case TarGz: compressedArtifacts = File.createTempFile(projectName + "-", ".tar.gz"); compressTarGzFile(compressedArtifacts, pathToCompress, listener); break; case None: throw new IllegalArgumentException("No compression type specified."); } } catch (final IOException e) { if (compressedArtifacts != null) { if (!compressedArtifacts.delete()) { compressedArtifacts.deleteOnExit(); } } throw e; } return compressedArtifacts; }
From source file:com.wcs.netbeans.liquiface.ui.wizards.appendchangelog.AppendToChangelogFileWizardAction.java
private File createTempChangelog() { File changelog = null; try {//from w w w.ja v a2s .c o m changelog = File.createTempFile("changelog", ".xml"); changelog.deleteOnExit(); } catch (IOException ex) { LOG().log(Level.SEVERE, null, ex); } return changelog; }
From source file:de.yaio.services.metaextract.server.extractor.TesseractExtractor.java
@Override public String extractText(final InputStream input, final String fileName, final String lang) throws IOException, ExtractorException { File tmpFile; tmpFile = File.createTempFile("metaextractor", "." + FilenameUtils.getExtension(fileName)); tmpFile.deleteOnExit(); Files.copy(input, tmpFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); return this.extractText(tmpFile, lang); }