List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:fll.web.GatherBugReport.java
/** * Add the database to the zipfile.//from w ww. j a v a2 s. c om * * @throws SQLException */ private static void addDatabase(final ZipOutputStream zipOut, final Connection connection, final Document challengeDocument) throws IOException, SQLException { ZipOutputStream dbZipOut = null; FileInputStream fis = null; try { final File temp = File.createTempFile("database", ".flldb"); dbZipOut = new ZipOutputStream(new FileOutputStream(temp)); DumpDB.dumpDatabase(dbZipOut, connection, challengeDocument); dbZipOut.close(); zipOut.putNextEntry(new ZipEntry("database.flldb")); fis = new FileInputStream(temp); IOUtils.copy(fis, zipOut); fis.close(); if (!temp.delete()) { temp.deleteOnExit(); } } finally { IOUtils.closeQuietly(dbZipOut); IOUtils.closeQuietly(fis); } }
From source file:azkaban.common.utils.Utils.java
public static File createTempDir(File parent) { File temp = new File(parent, Integer.toString(Math.abs(RANDOM.nextInt()) % 100000000)); temp.delete();/*from w ww. j av a2 s . c o m*/ temp.mkdir(); temp.deleteOnExit(); return temp; }
From source file:org.eclipse.cft.server.core.internal.CloudUtil.java
public static File createWarFile(IModule[] modules, Server server, IProgressMonitor monitor) throws CoreException { List<IStatus> result = new ArrayList<IStatus>(); try {/*ww w .j a v a 2s . co m*/ File tempFile = getTempFolder(modules[0]); // tempFile needs to be in the same location as the war file // otherwise PublishHelper will fail File targetFile = new File(tempFile, modules[0].getName() + ".war"); //$NON-NLS-1$ targetFile.deleteOnExit(); PublishHelper helper = new PublishHelper(tempFile); ArrayList<IModuleResource> resources = new ArrayList<IModuleResource>( Arrays.asList(server.getResources(modules))); IWebModule webModule = getWebModule(modules); if (webModule != null) { IModule[] children = webModule.getModules(); if (children != null) { for (IModule child : children) { String childUri = null; if (webModule != null) { childUri = webModule.getURI(child); } IJ2EEModule childModule = (IJ2EEModule) child.loadAdapter(IJ2EEModule.class, monitor); boolean isBinary = false; if (childModule != null) { isBinary = childModule.isBinary(); } if (isBinary) { // binaries are copied to the destination // directory if (childUri == null) { childUri = "WEB-INF/lib/" + child.getName(); //$NON-NLS-1$ } IPath jarPath = new Path(childUri); File jarFile = new File(tempFile, jarPath.lastSegment()); jarPath = jarPath.removeLastSegments(1); IModuleResource[] mr = server.getResources(new IModule[] { child }); IStatus[] status = helper.publishToPath(mr, new Path(jarFile.getAbsolutePath()), monitor); merge(result, status); resources.add(new ModuleFile(jarFile, jarFile.getName(), jarPath)); } else { // other modules are assembled into a jar if (childUri == null) { childUri = "WEB-INF/lib/" + child.getName() + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$ } IPath jarPath = new Path(childUri); File jarFile = new File(tempFile, jarPath.lastSegment()); jarPath = jarPath.removeLastSegments(1); IModuleResource[] mr = server.getResources(new IModule[] { child }); IStatus[] status = helper.publishZip(mr, new Path(jarFile.getAbsolutePath()), monitor); merge(result, status); resources.add(new ModuleFile(jarFile, jarFile.getName(), jarPath)); } } } } List<IModuleResource> newResources = new ArrayList<IModuleResource>(); for (IModuleResource mr : resources) { newResources.add(processModuleResource(mr)); } IStatus[] status = helper.publishZip(newResources.toArray(new IModuleResource[0]), new Path(targetFile.getAbsolutePath()), monitor); merge(result, status); throwException(result, "Publishing of " + modules[0].getName() + " failed"); //$NON-NLS-1$ //$NON-NLS-2$ return targetFile; } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID, "Failed to create war file: " + e.getMessage(), e)); //$NON-NLS-1$ } }
From source file:com.polyvi.xface.extension.advancedfiletransfer.FileUploader.java
/** * ??file/* w w w.j ava 2s . co m*/ * * @param in * @return * @throws IOException */ public static File createTempFile(InputStream in) throws IOException, IllegalArgumentException { if (null == in) { XLog.e(CLASS_NAME, "createTempFile methods: param is null"); throw new IllegalArgumentException(); } final File tempFile = File.createTempFile(PREFIX, SUFFIX); tempFile.deleteOnExit(); FileOutputStream out = new FileOutputStream(tempFile); try { byte[] buffer = new byte[XConstant.BUFFER_LEN]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } } catch (IOException e) { XLog.e(CLASS_NAME, "Create temp file failed"); throw new IOException(); } finally { if (null != out) { out.flush(); out.close(); } in.close(); } return tempFile; }
From source file:com.zacwolf.commons.crypto._CRYPTOfactory.java
static final File createTempFile(String name, String extension) throws IOException { final File file = File.createTempFile(name, extension); file.deleteOnExit(); return file;//from w w w . j av a 2 s . c o m }
From source file:com.baasbox.service.dbmanager.DbManagerService.java
public static void deleteExport(String fileName) throws FileNotFoundException, IOException { java.io.File file = new java.io.File(backupDir + fileSeparator + fileName); if (!file.exists()) { throw new FileNotFoundException("Export " + fileName + " not found"); } else {//from w w w . j a va 2 s.co m boolean deleted = false; try { FileUtils.forceDelete(file); deleted = true; } catch (IOException e) { deleted = file.delete(); if (deleted == false) { file.deleteOnExit(); } } if (!deleted) { throw new IOException("Unable to delete export.It will be deleted on the next reboot." + fileName); } } }
From source file:com.plugin.excel.xsd.node.store.impl.FileHelper.java
public static File getFilePointer(InputStream source, String destName) { File destination; try {/*from w w w . j a v a 2 s . co m*/ destination = File.createTempFile(destName, "temp"); if (!(destination.delete())) { throw new IOException("Could not delete temp file: " + destination.getAbsolutePath()); } if (!(destination.mkdir())) { throw new IOException("Could not create temp directory: " + destination.getAbsolutePath()); } FileUtils.copyInputStreamToFile(source, destination); destination.deleteOnExit(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.jaspersoft.studio.server.protocol.soap.SoapConnection.java
public static File writeToTemp(byte[] b64data) throws IOException { File inputFile = FileUtils.createTempFile("save", "jrxml"); inputFile.deleteOnExit(); FileOutputStream out = null;/*from w ww . j ava 2s. c o m*/ try { out = new FileOutputStream(inputFile); out.write(Base64.decodeBase64(b64data)); out.flush(); } finally { FileUtils.closeStream(out); } return inputFile; }
From source file:hadoop.UIUCWikifierAppHadoop.java
/** * Read in NER and NE default config files, write out new config files * with appropriate paths then save config file and return its location * @param pathToWikifierFiles/* ww w .j av a 2 s. c o m*/ * @return * @throws IOException * @throws FileNotFoundException */ private static String[] writeNewConfigFiles(String pathToWikifierFiles) throws FileNotFoundException, IOException { String[] configFiles = new String[3]; //read in old ner config parameters and change List<String> nerConfigLines = IOUtils .readLines(new FileInputStream(new File(pathToWikifierFiles + "/" + pathToDefaultNERConfigFile))); List<String> newNERConfigLines = new ArrayList<String>(); for (String l : nerConfigLines) { String[] values = l.split("\\t+"); StringBuilder newLine = new StringBuilder(); for (String value : values) { if (value.contains("/")) { newLine.append(pathToWikifierFiles + "/" + value); newLine.append("\t"); } else { newLine.append(value); newLine.append("\t"); } } newNERConfigLines.add(newLine.toString().trim()); } //write out new config parameters File newNERConfigFile = File.createTempFile("NER.config", ".tmp"); newNERConfigFile.deleteOnExit(); configFiles[0] = newNERConfigFile.getAbsolutePath(); BufferedWriter nerWriter = new BufferedWriter(new FileWriter(newNERConfigFile)); for (String l : newNERConfigLines) { System.out.println(l); nerWriter.write(l + "\n"); } nerWriter.close(); //read in old ne config parameters and change List<String> neConfigLines = IOUtils .readLines(new FileInputStream(new File(pathToWikifierFiles + "/" + pathToDefaultNEConfigFile))); List<String> newNEConfigLines = new ArrayList<String>(); for (String l : neConfigLines) { String[] values = l.split("="); String value = values[1]; if (value.contains("/")) { String[] paths = value.split("\\s+"); StringBuilder newValue = new StringBuilder(); for (String path : paths) { newValue.append(pathToWikifierFiles + "/" + path); newValue.append(" "); } StringBuilder newLine = new StringBuilder(); newLine.append(values[0]); newLine.append("="); newLine.append(newValue.toString().trim()); newNEConfigLines.add(newLine.toString()); } else { newNEConfigLines.add(l); } } //write out new config parameters File newNEConfigFile = File.createTempFile("config.txt", ".tmp"); newNEConfigFile.deleteOnExit(); configFiles[1] = newNEConfigFile.getAbsolutePath(); BufferedWriter neWriter = new BufferedWriter(new FileWriter(newNEConfigFile)); for (String l : newNEConfigLines) { neWriter.write(l + "\n"); } neWriter.close(); //read in old wordnet properties List<String> wordNetPropertiesLines = IOUtils .readLines(new FileInputStream(new File(pathToWikifierFiles + "/" + pathToDefaultJWNLConfigFile))); List<String> newWordNetPropertiesLines = new ArrayList<String>(); String replacementString = pathToWikifierFiles + "/data/WordNet/"; String stringToReplace = "data/WordNet/"; for (String l : wordNetPropertiesLines) { if (l.contains("dictionary_path")) { newWordNetPropertiesLines.add(l.replace(stringToReplace, replacementString)); } else { newWordNetPropertiesLines.add(l); } } File newWNConfigFile = File.createTempFile("jwnl_properties.xml", ".tmp"); newWNConfigFile.deleteOnExit(); configFiles[2] = newWNConfigFile.getAbsolutePath(); BufferedWriter wnWriter = new BufferedWriter(new FileWriter(newWNConfigFile)); for (String l : newWordNetPropertiesLines) { wnWriter.write(l + "\n"); } wnWriter.close(); return configFiles; }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducerarchive.utils.FilesUtils.java
/** * method to clean a specific repository * @param strTempDirectory name of repository *//*from w ww. j a va2 s.c o m*/ public static void cleanTemporyZipDirectory(String strTempDirectory) { File file = new File(strTempDirectory); if (file.isDirectory()) { File[] entries = file.listFiles(); int sz = entries.length; for (int j = 0; j < sz; j++) { cleanTemporyZipDirectory(entries[j].getPath()); } if (!file.delete()) { AppLogService.error(MESSAGE_DELETE_ERROR); } file.deleteOnExit(); } if (file.isFile()) { if (!file.delete()) { AppLogService.error(MESSAGE_DELETE_ERROR); } } }