List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:ProxyAuthTest.java
private static File writeArrayToByteStream(String url) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (url != null) { writeCmdLine("!connect " + url, out); }//w w w.ja v a 2 s .c o m writeCmdLine("!brief", out); writeCmdLine("!set silent true", out); resultFile = File.createTempFile(tabName, ".out"); if (!"true".equals(System.getProperty("proxyAuth.debug", "false"))) { resultFile.deleteOnExit(); } writeCmdLine("!record " + resultFile.getPath(), out); for (String stmt : dmlStmts) { writeSqlLine(stmt, out); } for (String stmt : selectStmts) { writeSqlLine(stmt, out); } for (String stmt : cleanUpStmts) { writeSqlLine(stmt, out); } writeCmdLine("!record", out); writeCmdLine("!quit", out); File tmpFile = File.createTempFile(tabName, ".q"); tmpFile.deleteOnExit(); scriptFileName = tmpFile.getPath(); FileOutputStream fstream = new FileOutputStream(scriptFileName); out.writeTo(fstream); inpStream = new ByteArrayInputStream(out.toByteArray()); return resultFile; }
From source file:com.amazonaws.codepipeline.jenkinsplugin.ExtractionTools.java
public static void deleteTemporaryCompressedFile(final File fileToDelete) throws IOException { if (fileToDelete.isDirectory()) { FileUtils.deleteDirectory(fileToDelete); } else {//from w ww .j ava 2 s. co m if (!fileToDelete.delete()) { fileToDelete.deleteOnExit(); } } }
From source file:com.sap.dirigible.ide.jgit.utils.GitFileUtils.java
private static void deleteFiles(File directory) { if (directory != null) { for (File file : directory.listFiles()) { if (file.isDirectory()) { deleteDirectory(file);//from w ww . j a va2 s . co m } if (!file.delete()) { file.deleteOnExit(); } } } }
From source file:org.openmrs.module.report.util.FileUtils.java
public synchronized static File createFileTemp(String fileName, String ext, byte[] bytes, File dir) { File tempFile = null; try {/*from ww w . j a va2 s.co m*/ tempFile = File.createTempFile(fileName, ext, dir); tempFile.deleteOnExit(); FileCopyUtils.copy(bytes, tempFile); } catch (Exception e) { // TODO: handle exception } return tempFile; }
From source file:org.openmrs.module.report.util.FileUtils.java
public synchronized static File createFileTemp(byte[] bytes) { File tempFile = null; try {/*from ww w .java 2s. c o m*/ tempFile = File.createTempFile("cms_graphic.gr", ".tmp"); tempFile.deleteOnExit(); FileCopyUtils.copy(bytes, tempFile); } catch (Exception e) { // TODO: handle exception } return tempFile; }
From source file:dk.netarkivet.viewerproxy.webinterface.Reporting.java
/** * Helper method to get result from a batchjob. * * @param batchJob a certain FileBatchJob * @return a file with the result./* w w w . java 2 s . c o m*/ */ private static File getResultFile(FileBatchJob batchJob) { File f; File fsorted; try { final String uuid = UUID.randomUUID().toString(); f = File.createTempFile("temp", uuid + ".txt", FileUtils.getTempDir()); f.deleteOnExit(); fsorted = File.createTempFile("temp", uuid + "-sorted.txt", FileUtils.getTempDir()); fsorted.deleteOnExit(); } catch (IOException e) { throw new IOFailure("Unable to create temporary file", e); } BatchStatus status = ArcRepositoryClientFactory.getViewerInstance().batch(batchJob, Settings.get(CommonSettings.USE_REPLICA_ID)); status.getResultFile().copyTo(f); FileUtils.sortCrawlLogOnTimestamp(f, fsorted); FileUtils.remove(f); return fsorted; }
From source file:com.github.seqware.queryengine.system.exporters.VCFDumper.java
/** * <p>dumpVCFFromFeatureSetID.</p> * * @param fSet a {@link com.github.seqware.queryengine.model.FeatureSet} object. * @param file a {@link java.lang.String} object. *//*www . j a va2 s .co m*/ public static void dumpVCFFromFeatureSetID(FeatureSet fSet, String file) { BufferedWriter outputStream = null; try { if (file != null) { outputStream = new BufferedWriter(new FileWriter(file)); } else { outputStream = new BufferedWriter(new OutputStreamWriter(System.out)); } outputStream.append("#CHROM POS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n"); } catch (IOException e) { Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown starting export to file:", e); System.exit(-1); } boolean caughtNonVCF = false; boolean mrSuccess = false; if (SWQEFactory.getQueryInterface() instanceof MRHBasePersistentBackEnd) { // hack to use VCF MR if (SWQEFactory.getModelManager() instanceof MRHBaseModelManager) { try { // pretend that the included com.github.seqware.queryengine.plugins.hbasemr.MRFeaturesByAttributesPlugin is an external plug-in Class<? extends PluginInterface> arbitraryPlugin; arbitraryPlugin = VCFDumperPlugin.class; // get a FeatureSet from the back-end QueryFuture<File> future = SWQEFactory.getQueryInterface().getFeaturesByPlugin(0, arbitraryPlugin, fSet); File get = future.get(); BufferedReader in = new BufferedReader(new FileReader(get)); IOUtils.copy(in, outputStream); in.close(); get.deleteOnExit(); outputStream.flush(); outputStream.close(); mrSuccess = true; } catch (IOException e) { // fail out on IO error Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown exporting to file:", e); System.exit(-1); } catch (Exception e) { Logger.getLogger(VCFDumper.class.getName()) .info("MapReduce exporting failed, falling-through to normal exporting to file"); // fall-through and do normal exporting if Map Reduce exporting fails } } // TODO: clearly this should be expanded to include closing database etc } if (mrSuccess) { return; } // fall-through if plugin-fails try { for (Feature feature : fSet) { StringBuffer buffer = new StringBuffer(); boolean caught = outputFeatureInVCF(buffer, feature); if (caught) { caughtNonVCF = true; } outputStream.append(buffer); outputStream.newLine(); } outputStream.flush(); } catch (IOException e) { Logger.getLogger(VCFDumper.class.getName()).fatal("Exception thrown exporting to file:", e); System.exit(-1); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:ch.ivyteam.ivy.maven.TestInstallEngineMojo.java
private static File createTempDir(String namePrefix) throws IOException { File tmpDir = Files.createTempDirectory(namePrefix).toFile(); tmpDir.deleteOnExit(); return tmpDir; }
From source file:com.edduarte.protbox.core.Constants.java
public static void delete(File fileToDelete) { if (fileToDelete == null) { return;/*from w ww .j a v a2s.co m*/ } if (!fileToDelete.exists()) { return; } try { deleter.delete(fileToDelete); } catch (IOException ex) { fileToDelete.deleteOnExit(); } }
From source file:de.egore911.versioning.deployer.performer.PerformExtraction.java
private static boolean extract(String uri, List<ExtractionPair> extractions) { URL url;// w ww .j a v a 2 s. com try { url = new URL(uri); } catch (MalformedURLException e) { LOG.error("Invalid URI: {}", e.getMessage(), e); return false; } try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); int response = connection.getResponseCode(); int lastSlash = uri.lastIndexOf('/'); if (lastSlash < 0) { LOG.error("Invalid URI: {}", uri); return false; } int lastDot = uri.lastIndexOf('.'); if (lastDot < 0) { LOG.error("Invalid URI: {}", uri); return false; } File downloadFile = File.createTempFile(uri.substring(lastSlash + 1), uri.substring(lastDot + 1)); downloadFile.deleteOnExit(); if (response == HttpURLConnection.HTTP_OK) { try (InputStream in = connection.getInputStream(); FileOutputStream out = new FileOutputStream(downloadFile)) { IOUtils.copy(in, out); } LOG.debug("Downloaded {} to {}", url, downloadFile.getAbsolutePath()); Set<ExtractionPair> usedExtractions = new HashSet<>(); // Perform extractions try (ZipFile zipFile = new ZipFile(downloadFile)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // Only extract files if (entry.isDirectory()) { continue; } for (ExtractionPair extraction : extractions) { String sourcePattern = extraction.source; if (FilenameUtils.wildcardMatch(entry.getName(), sourcePattern)) { usedExtractions.add(extraction); LOG.debug("Found matching file {} for source pattern {}", entry.getName(), sourcePattern); String filename = getSourcePatternMatch(entry.getName(), sourcePattern); // Workaround: If there is no matcher in 'sourcePattern' it will return the // complete path. Strip it down to the filename if (filename.equals(entry.getName())) { int lastIndexOf = filename.lastIndexOf('/'); if (lastIndexOf >= 0) { filename = filename.substring(lastIndexOf + 1); } } String name = UrlUtil.concatenateUrlWithSlashes(extraction.destination, filename); FileUtils.forceMkdir(new File(name).getParentFile()); try (InputStream in = zipFile.getInputStream(entry); FileOutputStream out = new FileOutputStream(name)) { IOUtils.copy(in, out); } LOG.debug("Extracted {} to {} from {}", entry.getName(), name, uri); } } } } for (ExtractionPair extraction : extractions) { if (!usedExtractions.contains(extraction)) { LOG.debug("Extraction {} to {} not used on {}", extraction.source, extraction.destination, uri); } } return true; } else { LOG.error("Could not download file: {}", uri); return false; } } catch (IOException e) { LOG.error("Could not download file: {}", e.getMessage(), e); return false; } }