List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:be.fedict.eid.tsl.Pkcs11Token.java
private String createPkcs11ProviderConfigFile() throws IOException { File tmpConfigFile = File.createTempFile("pkcs11-", "conf"); tmpConfigFile.deleteOnExit(); PrintWriter configWriter = new PrintWriter(new FileOutputStream(tmpConfigFile), true); configWriter.println("name=SmartCard"); configWriter.println("library=" + this.pkcs11Library); configWriter.println("slotListIndex= " + this.slotIdx); // configWriter.println("disabledMechanisms = {"); // configWriter.println("\tCKM_SHA1_RSA_PKCS"); // configWriter.println("}"); return tmpConfigFile.getAbsolutePath(); }
From source file:com.playonlinux.core.utils.archive.TarTest.java
private void testUncompress(String fileName) throws IOException { final File inputFile = new File(inputUrl.getPath(), fileName); final File temporaryDirectory = Files.createTempDir(); temporaryDirectory.deleteOnExit(); final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory); assertTrue(new File(temporaryDirectory, "directory1").isDirectory()); final File file1 = new File(temporaryDirectory, "file1.txt"); final File file2 = new File(temporaryDirectory, "file2.txt"); final File file0 = new File(new File(temporaryDirectory, "directory1"), "file0.txt"); assertTrue(file1.exists());/*from www.j a v a 2s . co m*/ assertTrue(file2.exists()); assertTrue(file0.exists()); assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1))); assertEquals("file2content", new String(FileUtils.readFileToByteArray(file2))); assertEquals("file0content", new String(FileUtils.readFileToByteArray(file0))); assertEquals(5, extractedFiles.size()); }
From source file:eu.scape_project.archiventory.container.TestContainer.java
/** * Create temporary files for the test container * * @param resourcePath Resource path//ww w . java 2s. co m * @return temporary file * @throws FileNotFoundException * @throws IOException */ private File createTempTestFile(String resourcePath) throws FileNotFoundException, IOException { InputStream testFileStream = TestContainer.class.getResourceAsStream(resourcePath); if (testFileStream == null) { throw new FileNotFoundException(resourcePath); } String filePath = extractDirectoryName + File.separator + resourcePath; File tmpTestFile = new File(filePath); Files.createParentDirs(tmpTestFile); tmpTestFile.deleteOnExit(); FileOutputStream fos = new FileOutputStream(tmpTestFile); IOUtils.copy(testFileStream, fos); fos.close(); return tmpTestFile; }
From source file:voldemort.ServerTestUtils.java
public static VoldemortConfig createServerConfig(boolean useNio, int nodeId, String baseDir, String clusterFile, String storeFile, Properties properties) throws IOException { Props props = new Props(); props.put("node.id", nodeId); props.put("voldemort.home", baseDir + "/node-" + nodeId); props.put("bdb.cache.size", 1 * 1024 * 1024); props.put("jmx.enable", "false"); props.put("enable.mysql.engine", "true"); props.loadProperties(properties);// w ww .j ava 2 s. c o m VoldemortConfig config = new VoldemortConfig(props); config.setMysqlDatabaseName("voldemort"); config.setMysqlUsername("voldemort"); config.setMysqlPassword("voldemort"); config.setStreamMaxReadBytesPerSec(10 * 1000 * 1000); config.setStreamMaxWriteBytesPerSec(10 * 1000 * 1000); config.setUseNioConnector(useNio); // clean and reinit metadata dir. File tempDir = new File(config.getMetadataDirectory()); tempDir.mkdirs(); tempDir.deleteOnExit(); File tempDir2 = new File(config.getDataDirectory()); tempDir2.mkdirs(); tempDir2.deleteOnExit(); // copy cluster.xml / stores.xml to temp metadata dir. if (null != clusterFile) FileUtils.copyFile(new File(clusterFile), new File(tempDir.getAbsolutePath() + File.separatorChar + "cluster.xml")); if (null != storeFile) FileUtils.copyFile(new File(storeFile), new File(tempDir.getAbsolutePath() + File.separatorChar + "stores.xml")); return config; }
From source file:com.googlecode.dex2jar.tools.Jar2Dex.java
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();//from w w w . j a v a 2 s . co m return; } File jar = new File(remainingArgs[0]); if (!jar.exists()) { System.err.println(jar + " is not exists"); usage(); return; } if (output == null) { if (jar.isDirectory()) { output = new File(jar.getName() + "-jar2dex.dex"); } else { output = new File(FilenameUtils.getBaseName(jar.getName()) + "-jar2dex.dex"); } } if (output.exists() && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); usage(); return; } File realJar; if (jar.isDirectory()) { realJar = File.createTempFile("d2j", ".jar"); realJar.deleteOnExit(); System.out.println("zipping " + jar + " -> " + realJar); OutHandler out = FileOut.create(realJar, true); try { new FileWalker().withStreamHandler(new OutAdapter(out)).walk(jar); } finally { IOUtils.closeQuietly(out); } } else { realJar = jar; } System.out.println("jar2dex " + realJar + " -> " + output); Class<?> c = Class.forName("com.android.dx.command.Main"); Method m = c.getMethod("main", String[].class); List<String> ps = new ArrayList<String>(); ps.addAll(Arrays.asList("--dex", "--no-strict", "--output=" + output.getCanonicalPath(), realJar.getCanonicalPath())); System.out.println("call com.android.dx.command.Main.main" + ps); m.invoke(null, new Object[] { ps.toArray(new String[0]) }); }
From source file:com.hortonworks.streamline.streams.catalog.configuration.ConfigFileWriterTest.java
@Test public void writeHadoopXmlConfigToFile() throws Exception { Map<String, String> configuration = createDummyConfiguration(); File destPath = Files.createTempFile("config", "xml").toFile(); destPath.deleteOnExit(); writer.writeConfigToFile(ConfigFileType.HADOOP_XML, configuration, destPath); assertTrue(destPath.exists());// ww w.j a va 2s .c o m try (InputStream is = new FileInputStream(destPath)) { String content = IOUtils.toString(is); System.out.println("Test print: XML content - " + content); assertTrue(content.trim().startsWith("<configuration>")); assertTrue(content.trim().endsWith("</configuration>")); assertTrue(content.contains("<property>")); assertTrue(content.contains("</property>")); for (Map.Entry<String, String> property : configuration.entrySet()) { assertTrue(content.contains("<name>" + property.getKey() + "</name>")); assertTrue(content.contains("<value>" + property.getValue() + "</value>")); } } }
From source file:com.talis.inject.guice.PropertiesConfiguredModuleFactoryTest.java
@Test(expected = ConfigurationException.class) public void invalidClassSpecifiedInFile() throws Exception { File tmpFile = File.createTempFile("injector-module", ".properties"); tmpFile.deleteOnExit(); FileUtils.writeStringToFile(tmpFile, String.format("%s=%s", PropertiesConfiguredModuleFactory.MODULE_PROPERTY, String.class.getName())); System.clearProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP); try {//from www . j a va 2 s. c om System.setProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP, tmpFile.getAbsolutePath()); new PropertiesConfiguredModuleFactory().getModules(); } finally { System.clearProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP); } }
From source file:com.talis.inject.guice.PropertiesConfiguredModuleFactoryTest.java
@Test public void returnEmptyListIfModulesSpecifiedInFile() throws Exception { File tmpFile = File.createTempFile("injector-module", ".properties"); tmpFile.deleteOnExit(); FileUtils.writeStringToFile(tmpFile, "some.other.property=SomeRandomValue"); System.clearProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP); try {//from w w w. java2 s. c o m System.setProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP, tmpFile.getAbsolutePath()); Module[] modules = new PropertiesConfiguredModuleFactory().getModules(); assertEquals(0, modules.length); } finally { System.clearProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP); } }
From source file:gobblin.converter.http.AvroToRestJsonEntryConverterTest.java
private void testConversion(RestEntry<JsonObject> expected, WorkUnitState actualWorkUnitState) throws DataConversionException, IOException, JSONException { Schema schema = new Schema.Parser().parse(getClass().getResourceAsStream("/converter/nested.avsc")); GenericDatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema); File tmp = File.createTempFile(this.getClass().getSimpleName(), null); tmp.deleteOnExit(); try {/*from ww w . j ava2s. c o m*/ FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/converter/nested.avro"), tmp); DataFileReader<GenericRecord> dataFileReader = new DataFileReader<GenericRecord>(tmp, datumReader); GenericRecord avroRecord = dataFileReader.next(); AvroToRestJsonEntryConverter converter = new AvroToRestJsonEntryConverter(); RestEntry<JsonObject> actual = converter.convertRecord(null, avroRecord, actualWorkUnitState).iterator() .next(); Assert.assertEquals(actual.getResourcePath(), expected.getResourcePath()); JSONAssert.assertEquals(expected.getRestEntryVal().toString(), actual.getRestEntryVal().toString(), false); converter.close(); dataFileReader.close(); } finally { if (tmp != null) { tmp.delete(); } } }
From source file:com.imaginea.kodebeagle.base.util.Utils.java
@NotNull public String createFileWithContents(final String displayFileName, final String contents, final String baseDir, final String digest) throws IOException { final String fileParentPath = String.format("%s%c%s", baseDir, File.separatorChar, digest); final File parentDir = new File(fileParentPath); FileUtil.createDirectory(parentDir); parentDir.deleteOnExit(); final String fullFilePath = String.format("%s%c%s", parentDir.getAbsolutePath(), File.separatorChar, displayFileName);//from w ww . j av a2 s . c o m final File file = new File(fullFilePath); if (!file.exists()) { FileUtil.createIfDoesntExist(file); forceWrite(contents, file); file.deleteOnExit(); } return fullFilePath; }