List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:com.fizzed.blaze.ssh.SshIntegrationTest.java
@Test public void sftpPutAndGet() throws Exception { Path exampleFile = FileHelper.resourceAsPath("/example/test1.txt"); try (SshSession ssh = sshConnect(uri).configFile(sshConfigFile).run()) { try (SshSftpSession sftp = SecureShells.sshSftp(ssh).run()) { // make sure file does not exist on remote system sshExec(ssh, "rm", "-f", "test1.txt").run(); sftp.put().source(exampleFile).target(exampleFile.getFileName()).run(); File tempFile = File.createTempFile("blaze.", ".sshtest"); tempFile.deleteOnExit(); sftp.get().source(exampleFile.getFileName()).target(tempFile).run(); // files match? assertTrue("The files differ!", FileUtils.contentEquals(tempFile, exampleFile.toFile())); }/*from w w w . j a v a 2s. co m*/ } }
From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlistParserTest.java
@Test public void save() throws Exception { JAXBPlistParser parser = new JAXBPlistParser(); Plist plist = parser.load(fileName); File output = File.createTempFile("proj", ".pbxproj"); output.deleteOnExit(); parser.save(plist, output.getAbsolutePath()); DocumentBuilder db = initDocumentBuilder(); Document expected = db.parse(new File(fileName)); Document actual = db.parse(output); assertXMLEqual(expected, actual);// w w w . j a v a 2s . c o m }
From source file:com.redhat.rhn.frontend.graphing.test.GraphGeneratorTest.java
public void testEmptyGraphFile() throws Exception { File f = GraphGenerator.getInstance().generateGraphFile(makeTestGraph(0), 800, 240); assertNotNull(f.getAbsolutePath());/*from w ww. ja v a 2 s . c o m*/ f.deleteOnExit(); }
From source file:com.googlecode.dex2jar.tools.ApkSign.java
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();//from ww w . ja v a2s . c om return; } File apkIn = new File(remainingArgs[0]); if (!apkIn.exists()) { System.err.println(apkIn + " is not exists"); usage(); return; } if (output == null) { if (apkIn.isDirectory()) { output = new File(apkIn.getName() + "-signed.apk"); } else { output = new File(FilenameUtils.getBaseName(apkIn.getName()) + "-signed.apk"); } } if (output.exists() && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); usage(); return; } File realJar; if (apkIn.isDirectory()) { realJar = File.createTempFile("d2j", ".jar"); realJar.deleteOnExit(); System.out.println("zipping " + apkIn + " -> " + realJar); OutHandler out = FileOut.create(realJar, true); try { new FileWalker().withStreamHandler(new OutAdapter(out)).walk(apkIn); } finally { IOUtils.closeQuietly(out); } } else { realJar = apkIn; } CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) certificateFactory .generateCertificate(ApkSign.class.getResourceAsStream("ApkSign.cer")); KeyFactory rSAKeyFactory = KeyFactory.getInstance("RSA"); PrivateKey privateKey = rSAKeyFactory.generatePrivate( new PKCS8EncodedKeySpec(IOUtils.toByteArray(ApkSign.class.getResourceAsStream("ApkSign.private")))); Class<?> clz; try { clz = Class.forName("com.android.signapk.SignApk"); } catch (ClassNotFoundException cnfe) { System.err.println("please run d2j-apk-sign in a sun compatible JRE (contains sun.security.*)"); return; } Method m = clz.getMethod("sign", X509Certificate.class, PrivateKey.class, boolean.class, File.class, File.class); m.setAccessible(true); System.out.println("sign " + realJar + " -> " + output); m.invoke(null, cert, privateKey, this.signWhole, realJar, output); }
From source file:io.druid.emitter.ambari.metrics.WhiteListBasedDruidToTimelineEventConverterTest.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 v a 2 s. co m*/ } WhiteListBasedDruidToTimelineEventConverter converter = new WhiteListBasedDruidToTimelineEventConverter( prefix, "druid", mapFile.getAbsolutePath(), new DefaultObjectMapper()); ServiceMetricEvent event = new ServiceMetricEvent.Builder().setDimension("gcName", new String[] { "g1" }) .build(createdTime, "jvm/gc/cpu", 10).build(serviceName, hostname); TimelineMetric metric = converter.druidEventToTimelineMetric(event); Assert.assertNotNull(metric); Assert.assertEquals(defaultNamespace + ".g1.jvm/gc/cpu", metric.getMetricName()); }
From source file:gobblin.data.management.copy.recovery.RecoveryHelperTest.java
@Test public void testPurge() throws Exception { String content = "contents"; File persistDirBase = Files.createTempDir(); persistDirBase.deleteOnExit(); State state = new State(); state.setProp(RecoveryHelper.PERSIST_DIR_KEY, persistDirBase.getAbsolutePath()); state.setProp(RecoveryHelper.PERSIST_RETENTION_KEY, "1"); RecoveryHelper recoveryHelper = new RecoveryHelper(FileSystem.getLocal(new Configuration()), state); File persistDir = new File(RecoveryHelper.getPersistDir(state).get().toString()); persistDir.mkdir();//from w ww .ja v a2s. co m File file = new File(persistDir, "file1"); OutputStream os = new FileOutputStream(file); IOUtils.write(content, os); os.close(); file.setLastModified(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(2)); File file2 = new File(persistDir, "file2"); OutputStream os2 = new FileOutputStream(file2); IOUtils.write(content, os2); os2.close(); Assert.assertEquals(persistDir.listFiles().length, 2); recoveryHelper.purgeOldPersistedFile(); Assert.assertEquals(persistDir.listFiles().length, 1); }
From source file:com.github.brandtg.stl.PlotTest.java
@Test public void testPlot() throws Exception { final ObjectMapper objectMapper = new ObjectMapper(); final JsonNode tree = objectMapper .readTree(new File(this.getClass().getResource("/sample-timeseries.json").getFile())); final int n = tree.get("times").size(); final double[] ts = new double[n]; final double[] ys = new double[n]; for (int i = 0; i < n; i++) { ts[i] = tree.get("times").get(i).asDouble(); ys[i] = tree.get("series").get(i).asDouble(); }// w w w. j av a 2 s . c o m final StlDecomposition stl = new StlDecomposition(12); final StlResult res = stl.decompose(ts, ys); final File output = new File("seasonal.png"); final File hourly = new File("stl-hourly.png"); output.deleteOnExit(); hourly.deleteOnExit(); StlPlotter.plot(res, "New Title", Hour.class, hourly); StlPlotter.plot(res, output); StlPlotter.plot(res); Assert.assertTrue(output.exists()); Assert.assertTrue(hourly.exists()); final File exists = new File("stl-decomposition.png"); exists.deleteOnExit(); StlPlotter.plot(res, "Test Title"); Assert.assertTrue(exists.exists()); }
From source file:org.openqa.selenium.environment.webserver.AppServerTest.java
@Test public void uploadsFile() throws Throwable { String FILE_CONTENTS = "Uploaded file"; File testFile = File.createTempFile("webdriver", "tmp"); testFile.deleteOnExit(); Files.write(FILE_CONTENTS, testFile, Charsets.UTF_8); driver.get(server.whereIs("upload.html")); driver.findElement(By.id("upload")).sendKeys(testFile.getAbsolutePath()); driver.findElement(By.id("go")).submit(); // Nasty. Sorry. Thread.sleep(50);//from w w w . ja v a 2s . co m driver.switchTo().frame("upload_target"); WebElement body = driver.findElement(By.xpath("//body")); assertEquals(FILE_CONTENTS, body.getText()); }
From source file:org.openqa.selenium.environment.webserver.AppServerTestBase.java
@Test public void uploadsFile() throws Throwable { String FILE_CONTENTS = "Uploaded file"; File testFile = File.createTempFile("webdriver", "tmp"); testFile.deleteOnExit(); Files.asCharSink(testFile, StandardCharsets.UTF_8).write(FILE_CONTENTS); driver.get(server.whereIs("upload.html")); driver.findElement(By.id("upload")).sendKeys(testFile.getAbsolutePath()); driver.findElement(By.id("go")).submit(); // Nasty. Sorry. Thread.sleep(50);// w w w. ja v a 2 s.c o m driver.switchTo().frame("upload_target"); WebElement body = driver.findElement(By.xpath("//body")); assertEquals(FILE_CONTENTS, body.getText()); }