List of usage examples for org.apache.commons.io FileUtils forceDeleteOnExit
public static void forceDeleteOnExit(File file) throws IOException
From source file:org.opencredo.cloud.storage.jcloud.JCloudAWSIntegrationTest.java
@Test public void testRealFileUpload() throws IOException { template.send(BUCKET_NAME, KEY, TEST_FILE); File f = File.createTempFile(getClass().getSimpleName(), ".txt"); FileUtils.forceDeleteOnExit(f); template.receiveAndSaveToFile(BUCKET_NAME, KEY, f); String receivedFileContent = FileUtils.readFileToString(f); System.out.println("Received file content: " + receivedFileContent); String orgFileContent = FileUtils.readFileToString(TEST_FILE); assertEquals("File content does not match", orgFileContent, receivedFileContent); }
From source file:org.opencredo.cloud.storage.jcloud.JCloudAzureIntegrationTest.java
@Test public void testRealFileUpload() throws StorageCommunicationException, IOException { template.send(BUCKET_NAME, KEY, TEST_FILE); File f = File.createTempFile(getClass().getSimpleName(), ".txt"); FileUtils.forceDeleteOnExit(f); template.receiveAndSaveToFile(BUCKET_NAME, KEY, f); String receivedFileContent = FileUtils.readFileToString(f); System.out.println("Received file content: " + receivedFileContent); String orgFileContent = FileUtils.readFileToString(TEST_FILE); assertEquals("File content does not match", orgFileContent, receivedFileContent); }
From source file:org.opencredo.cloud.storage.jcloud.JCloudFileIntegrationTest.java
@Test public void testRealFileUpload() throws IOException { template.send(BUCKET_NAME, KEY, TEST_FILE); File f = File.createTempFile(getClass().getSimpleName(), ".txt"); FileUtils.forceDeleteOnExit(f); template.receiveAndSaveToFile(BUCKET_NAME, KEY, f); String receivedFileContent = FileUtils.readFileToString(f); System.out.println("Received file content: " + receivedFileContent); String orgFileContent = FileUtils.readFileToString(TEST_FILE); assertEquals("File content does not match: " + orgFileContent + " - compared to -" + receivedFileContent, orgFileContent, receivedFileContent); }
From source file:org.opencredo.cloud.storage.s3.JCloudS3TemplateIntegrationTest.java
@Test public void testCreateTimeExpiredUrl() throws IOException { template.send(BUCKET_NAME, KEY, TEST_FILE); File f = File.createTempFile(getClass().getSimpleName(), ".txt"); FileUtils.forceDeleteOnExit(f); template.receiveAndSaveToFile(BUCKET_NAME, KEY, f); String receivedFileContent = FileUtils.readFileToString(f); System.out.println("Received file content: " + receivedFileContent); String orgFileContent = FileUtils.readFileToString(TEST_FILE); assertEquals("File content does not match", orgFileContent, receivedFileContent); // Determine what the time will be in 5 minutes. Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 5);/* w w w .j a v a 2s . c o m*/ Date expiryDate = cal.getTime(); try { template.createdSignedUrl(BUCKET_NAME, KEY, expiryDate); assertFalse("Exception should have been thrown", true); } catch (StorageCommunicationException e) { assertTrue("Exception was thrown correctly", true); } }
From source file:org.opencredo.cloud.storage.s3.JetS3TemplateIntegrationTest.java
@Test public void testCreateTimeExpiredUrl() throws StorageCommunicationException, IOException { template.send(BUCKET_NAME, KEY, TEST_FILE); File f = File.createTempFile(getClass().getSimpleName(), ".txt"); FileUtils.forceDeleteOnExit(f); template.receiveAndSaveToFile(BUCKET_NAME, KEY, f); String receivedFileContent = FileUtils.readFileToString(f); System.out.println("Received file content: " + receivedFileContent); String orgFileContent = FileUtils.readFileToString(TEST_FILE); assertEquals("File content does not match", orgFileContent, receivedFileContent); // Determine what the time will be in 5 minutes. Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 5);//w ww . j a v a 2 s . co m Date expiryDate = cal.getTime(); String url = template.createdSignedUrl(BUCKET_NAME, KEY, expiryDate); assertNotNull(url); System.out.println("Url retrieved " + url); }
From source file:org.openengsb.labs.paxexam.karaf.container.internal.KarafTestContainer.java
@Override public synchronized TestContainer stop() { LOGGER.debug("Shutting down the test container (Pax Runner)"); try {/*from ww w.jav a 2 s .c o m*/ if (started) { target.stop(); RemoteBundleContextClient remoteBundleContextClient = target.getClientRBC(); if (remoteBundleContextClient != null) { remoteBundleContextClient.stop(); } if (runner != null) { runner.shutdown(); } } else { throw new RuntimeException("Container never came up"); } } finally { started = false; target = null; if (deleteRuntime) { system.clear(); try { FileUtils.forceDelete(targetFolder); } catch (IOException e) { 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..."); } } } } return this; }
From source file:org.openremote.controller.service.impl.FileServiceImpl.java
public boolean writeZipAndUnzip(InputStream inputStream) { String resourcePath = configuration.getResourcePath(); File zip = new File(resourcePath, "openremote.zip"); FileOutputStream fos = null;//from w ww.jav a2 s . c o m try { if (!zip.getParentFile().exists()) { FileUtils.forceMkdir(zip); } FileUtils.forceDeleteOnExit(zip); fos = new FileOutputStream(zip); byte[] buffer = new byte[1024]; int len = 0; while ((len = inputStream.read(buffer)) != -1) { fos.write(buffer, 0, len); } if (!ZipUtil.unzip(zip, resourcePath)) { return false; } logger.info("unzip " + zip.getAbsolutePath() + " success."); FileUtils.forceDeleteOnExit(zip); } catch (IOException e) { logger.error("Can't write openremote.zip to " + resourcePath, e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { logger.debug("failed to close input stream of " + zip.getAbsolutePath()); } } if (fos != null) { try { fos.close(); } catch (IOException e) { logger.debug("failed to close file output stream of " + zip.getAbsolutePath()); } } } copyLircdConf(resourcePath); return true; }
From source file:org.pentaho.platform.plugin.services.importer.SolutionImportHandlerNamingIT.java
@BeforeClass public static void beforeClass() throws IOException { tempDir = File.createTempFile("test", null); tempDir.delete();/*from w w w. j a va2s .c o m*/ tempDir.mkdir(); FileUtils.forceDeleteOnExit(tempDir); solutionDir = new File(getSolutionPath()); assertTrue(solutionDir.exists()); assertTrue(solutionDir.isDirectory()); }
From source file:org.pentaho.platform.plugin.services.importexport.ZipExportProcessorTest.java
@BeforeClass public static void beforeClass() throws IOException { tempDir = File.createTempFile("test", null); tempDir.delete();//from ww w . j a va 2 s. co m tempDir.mkdir(); FileUtils.forceDeleteOnExit(tempDir); }
From source file:org.polymap.biotop.model.importer.WaldbiotopeImportWizard.java
protected File[] unpackZip(InputStream in) throws ZipException, IOException { ZipInputStream zip = new ZipInputStream(in); try {//w w w. ja v a 2s . c o m zipDir = Files.createTempDirectory(WaldbiotopeImportOperation.class.getSimpleName()).toFile(); FileUtils.forceDeleteOnExit(zipDir); ZipEntry entry = null; while ((entry = zip.getNextEntry()) != null) { log.info("ZIP entry: " + entry); File f = new File(zipDir, entry.getName()); Files.copy(zip, f.toPath()); } return zipDir.listFiles(); } catch (Throwable e) { log.warn("", e); throw new RuntimeException(e); } finally { IOUtils.closeQuietly(zip); } }