List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:com.premiumminds.persistence.utils.HibernateDDLTest.java
@Test public void testCreateCommandWithFile() throws Exception { File file = File.createTempFile("updatedb", ".sql"); file.deleteOnExit(); String[] args = new String[] { "--create", "application-data-unit-export-test", file.getAbsolutePath() }; HibernateDDL.main(args);/*from www . j a v a2 s.co m*/ assertTrue(outContent.toString().isEmpty()); assertEquals("\n" + " create table FooBar (\n" + " id integer not null,\n" + " bar integer not null,\n" + " foo varchar(255),\n" + " primary key (id)\n" + " );\n", IOUtils.toString(new FileReader(file))); }
From source file:com.searchbox.framework.service.DirectoryService.java
public File createFile(String fname) { Resource tempDir = context.getResource("WEB-INF/temp/"); if (!tempDir.exists()) { try {/*from www . jav a 2 s . co m*/ tempDir.getFile().mkdirs(); } catch (IOException e) { LOGGER.error("Could not create temp file in directoryService", e); } } try { File newFile = new File(tempDir.getFile().getAbsolutePath() + "/" + fname); newFile.deleteOnExit(); return newFile; } catch (IOException e) { LOGGER.error("Could not create temp file in directoryService", e); } return null; }
From source file:io.github.zlika.reproducible.ZipStripper.java
@Override public void strip(File in, File out) throws IOException { try (final ZipFile zip = new ZipFile(in); final ZipArchiveOutputStream zout = new ZipArchiveOutputStream(out)) { final List<String> sortedNames = sortEntriesByName(zip.getEntries()); for (String name : sortedNames) { final ZipArchiveEntry entry = zip.getEntry(name); // Strip Zip entry final ZipArchiveEntry strippedEntry = filterZipEntry(entry); // Strip file if required final Stripper stripper = getSubFilter(name); if (stripper != null) { // Unzip entry to temp file final File tmp = File.createTempFile("tmp", null); tmp.deleteOnExit(); Files.copy(zip.getInputStream(entry), tmp.toPath(), StandardCopyOption.REPLACE_EXISTING); final File tmp2 = File.createTempFile("tmp", null); tmp2.deleteOnExit();// w w w . j a v a 2s . co m stripper.strip(tmp, tmp2); final byte[] fileContent = Files.readAllBytes(tmp2.toPath()); strippedEntry.setSize(fileContent.length); zout.putArchiveEntry(strippedEntry); zout.write(fileContent); zout.closeArchiveEntry(); } else { // Copy the Zip entry as-is zout.addRawArchiveEntry(strippedEntry, getRawInputStream(zip, entry)); } } } }
From source file:com.premiumminds.persistence.utils.HibernateDDLTest.java
@Test public void testUpdateCommandWithFile() throws Exception { File file = File.createTempFile("updatedb", ".sql"); file.deleteOnExit(); String[] args = new String[] { "--update", "application-data-unit-export-test", "jdbc:h2:" + getClass().getResource("/foobar.mv.db").getFile().replace(".mv.db", ""), "foo", "bar", file.getAbsolutePath() };//from w w w. j a va 2 s . co m HibernateDDL.main(args); assertTrue(outContent.toString().isEmpty()); assertEquals("\n alter table FooBar \n add column bar integer not null;\n", IOUtils.toString(new FileReader(file))); }
From source file:eu.ggnet.dwoss.util.ImageFinder.java
public ImageFinder(String filePath) { this.path = filePath == null ? null : new File(filePath); //Setup the error URL try {/*ww w . ja v a2 s. c o m*/ File errorFile = File.createTempFile("error", ".png"); errorFile.deleteOnExit(); FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("error.png"), errorFile); errorUrl = errorFile.toURI().toURL(); } catch (IOException ex) { throw new RuntimeException("Error in activating Fallback mode.", ex); } // The No Image. try { File noimageFile = File.createTempFile("noimage", ".png"); noimageFile.deleteOnExit(); FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("noimage.png"), noimageFile); noimageUrl = noimageFile.toURI().toURL(); } catch (IOException ex) { throw new RuntimeException("Error in creating the noimgae", ex); } }
From source file:com.legstar.zosjes.ZosUploadMojoTest.java
/** * Return a test pom where variables have been replaced by actual values. * //from www . j av a 2s. c o m * @throws IOException if test pom cannot be read */ protected File getTestPom() throws IOException { File testPom = new File(getBasedir(), "target/test-classes/unit/basic-test-plugin-config.xml"); String testPomStr = FileUtils.readFileToString(testPom); testPomStr = testPomStr.replace("${" + HostSettings.HOST_NAME_TAG + "}", _hostSettings.getHostName()); testPomStr = testPomStr.replace("${" + HostSettings.HOST_USER_ID_TAG + "}", _hostSettings.getHostUserId()); testPomStr = testPomStr.replace("${" + HostSettings.HOST_PASSWORD_TAG + "}", _hostSettings.getHostPassword()); File tempPom = File.createTempFile("legstar", "test.pom.xml"); tempPom.deleteOnExit(); FileUtils.writeStringToFile(tempPom, testPomStr); return tempPom; }
From source file:com.premiumminds.persistence.utils.HibernateDDLTest.java
@Test public void testCreateDropCommandWithFile() throws Exception { File file = File.createTempFile("updatedb", ".sql"); file.deleteOnExit(); String[] args = new String[] { "--create-drop", "application-data-unit-export-test", file.getAbsolutePath() };/*from w w w . j ava2s . c o m*/ HibernateDDL.main(args); assertTrue(outContent.toString().isEmpty()); assertEquals( "\n" + " drop table FooBar if exists;\n" + "\n" + " create table FooBar (\n" + " id integer not null,\n" + " bar integer not null,\n" + " foo varchar(255),\n" + " primary key (id)\n" + " );\n", IOUtils.toString(new FileReader(file))); }
From source file:org.openmrs.module.kenyaemr.page.controller.AdminSoftwareVersionPageController.java
public void controller(PageModel model, @RequestParam(value = "priorVersion", required = false) String priorVersion, HttpServletRequest request) {/* w ww .j a v a2 s .c om*/ model.addAttribute("priorVersion", null); model.addAttribute("log", null); if (request instanceof MultipartHttpServletRequest) { MultipartFile uploaded = ((MultipartHttpServletRequest) request).getFile("distributionZip"); if (uploaded != null) { // write this to a known file on disk, so we can use ZipFile, since ZipInputStream is buggy File file = null; try { file = File.createTempFile("distribution", ".zip"); file.deleteOnExit(); FileUtils.copyInputStreamToFile(uploaded.getInputStream(), file); List<String> log = Context.getService(ModuleDistroService.class).uploadDistro(file, request.getSession().getServletContext()); model.addAttribute("log", log); model.addAttribute("priorVersion", priorVersion); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); model.addAttribute("log", Arrays.asList("Error", ex.getMessage(), sw.toString())); } } } String currentVersion = ModuleFactory.getModuleById("kenyaemr").getVersion(); model.put("currentKenyaEmrVersion", currentVersion); }
From source file:com.mindquarry.jcr.jackrabbit.JackrabbitRMIRepositoryStandalone.java
private String createDefaultRepoConf() throws IOException { InputStream confIn = getClass().getResourceAsStream(REPO_CONF_PATH); File tempConfFile = File.createTempFile("repository", "xml"); tempConfFile.deleteOnExit(); IOUtils.copy(confIn, new FileOutputStream(tempConfFile)); return tempConfFile.getAbsolutePath(); }
From source file:eu.ggnet.dwoss.util.FileJacket.java
/** * Creates a temporary File with the content of this DataFile, deletes on exit. * <p/>/*from www.j a v a 2s . c o m*/ * @return the file pointing to the temporary one. */ public File toTemporaryFile() { File f; try { f = File.createTempFile(head + "_", suffix); f.deleteOnExit(); } catch (IOException ex) { throw new RuntimeException("Temporary File creation not done.", ex); } try (FileOutputStream os = new FileOutputStream(f)) { IOUtils.write(content, os); } catch (IOException ex) { throw new RuntimeException("Temporary File creation not done.", ex); } return f; }