List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.PlanPlotter.java
public static void printLogicalPlan(ILogicalPlan plan) throws AlgebricksException { int indent = 5; StringBuilder out = new StringBuilder(); int randomInt = 10000 + randomGenerator.nextInt(100); appendln(out, "digraph G {"); for (Mutable<ILogicalOperator> root : plan.getRoots()) { printVisualizationGraph((AbstractLogicalOperator) root.getValue(), indent, out, "", randomInt); }/*from w w w . j a v a 2 s .co m*/ appendln(out, "\n}\n}"); try { File file = File.createTempFile("logicalPlan", ".txt"); FileUtils.writeStringToFile(file, out.toString()); file.deleteOnExit(); } catch (IOException e) { e.printStackTrace(); } }
From source file:be.i8c.sag.util.FileUtils.java
/** * Receives the fop.xconf stream and puts it in a temporary file. * * @param stream The stream tat will be written to the temporary file * @return Returns temporary file with the content of the stream * @throws IOException when the file couldn't be created */// w w w . j av a 2 s . c om public static File createTempFopConf(InputStream stream) throws IOException { File temp; temp = File.createTempFile("fop", ".xconf"); temp.deleteOnExit(); FileOutputStream out = new FileOutputStream(temp); IOUtils.copy(stream, out); return temp; }
From source file:com.thoughtworks.go.helpers.FileSystemUtils.java
public static File createDirectory(String directoryName, String parent) { File directory = new File(getTestRootDir(), parent + File.separator + directoryName); deleteDirectory(directory);// www . ja va2 s .c om directory.mkdir(); directory.deleteOnExit(); return directory; }
From source file:mobac.program.EnvironmentSetup.java
protected static void checkDirectory(File dir, String dirName, boolean checkIsWriteable) { try {//w w w. ja v a2 s . co m Utilities.mkDirs(dir); } catch (IOException e) { GUIExceptionHandler.processFatalExceptionSimpleDialog("Error while creating " + dirName + " directory\n" + dir.getAbsolutePath() + "\nProgram will exit.", e); } if (!checkIsWriteable) return; try { // test if we can write into that directory File testFile = File.createTempFile("MOBAC", "", dir); testFile.createNewFile(); testFile.deleteOnExit(); testFile.delete(); } catch (IOException e) { GUIExceptionHandler.processFatalExceptionSimpleDialog("Unable to write to " + dirName + "\n" + dir.getAbsolutePath() + "\nPlease correct file permissions and restart MOBAC", e); } }
From source file:javarestart.Utils.java
static File fetchResourceToTempFile(String resName, String resExt, InputStream from) { File temp; try {/*from ww w. jav a 2 s . co m*/ temp = File.createTempFile(resName, resExt); } catch (IOException e) { return null; } temp.deleteOnExit(); try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(temp))) { copy(from, os); } catch (IOException e) { e.printStackTrace(); return null; } return temp; }
From source file:edu.unc.lib.dl.util.FileUtils.java
/** * Creates a temporary copy of the original file or folder. * * @param file/* w w w .j a va 2s.com*/ * the original file * @return the temporary file */ public static File tempCopy(File file) { try { File result = File.createTempFile("tempCopy", ""); result.deleteOnExit(); copyFolder(file, result); return result; } catch (IOException e) { throw new Error("Unexpected", e); } }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.PlanPlotter.java
public static void printOptimizedLogicalPlan(ILogicalPlan plan) throws AlgebricksException { int indent = 5; StringBuilder out = new StringBuilder(); int randomInt = 10000 + randomGenerator.nextInt(100); appendln(out, "digraph G {"); for (Mutable<ILogicalOperator> root : plan.getRoots()) { printVisualizationGraph((AbstractLogicalOperator) root.getValue(), indent, out, "", randomInt); }// w w w . j a v a 2 s .com appendln(out, "\n}\n}"); try { File file = File.createTempFile("logicalOptimizedPlan", ".txt"); FileUtils.writeStringToFile(file, out.toString()); file.deleteOnExit(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ml.dmlc.xgboost4j.java.NativeLibLoader.java
/** * Create a temp file that copies the resource from current JAR archive * <p/>/* w w w.ja v a2 s . com*/ * The file from JAR is copied into system temp file. * The temporary file is deleted after exiting. * Method uses String as filename because the pathname is "abstract", not system-dependent. * <p/> * The restrictions of {@link File#createTempFile(java.lang.String, java.lang.String)} apply to * {@code path}. * @param path Path to the resources in the jar * @return The created temp file. * @throws IOException * @throws IllegalArgumentException */ static String createTempFileFromResource(String path) throws IOException, IllegalArgumentException { // Obtain filename from path if (!path.startsWith("/")) { throw new IllegalArgumentException("The path has to be absolute (start with '/')."); } String[] parts = path.split("/"); String filename = (parts.length > 1) ? parts[parts.length - 1] : null; // Split filename to prexif and suffix (extension) String prefix = ""; String suffix = null; if (filename != null) { parts = filename.split("\\.", 2); prefix = parts[0]; suffix = (parts.length > 1) ? "." + parts[parts.length - 1] : null; // Thanks, davs! :-) } // Check if the filename is okay if (filename == null || prefix.length() < 3) { throw new IllegalArgumentException("The filename has to be at least 3 characters long."); } // Prepare temporary file File temp = File.createTempFile(prefix, suffix); temp.deleteOnExit(); if (!temp.exists()) { throw new FileNotFoundException("File " + temp.getAbsolutePath() + " does not exist."); } // Prepare buffer for data copying byte[] buffer = new byte[1024]; int readBytes; // Open and check input stream InputStream is = NativeLibLoader.class.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("File " + path + " was not found inside JAR."); } // Open output stream and copy data between source file in JAR and the temporary file OutputStream os = new FileOutputStream(temp); try { while ((readBytes = is.read(buffer)) != -1) { os.write(buffer, 0, readBytes); } } finally { // If read/write fails, close streams safely before throwing an exception os.close(); is.close(); } return temp.getAbsolutePath(); }
From source file:io.cloudslang.content.httpclient.build.auth.AuthSchemeProviderLookupBuilder.java
private static File createKrb5Configuration(String domain) throws IOException { File tempFile = File.createTempFile("krb", "kdc"); tempFile.deleteOnExit(); ArrayList<String> lines = new ArrayList<>(); lines.add("[libdefaults]"); lines.add("\tdefault_realm = " + domain.toUpperCase()); lines.add("[realms]"); lines.add("\t" + domain.toUpperCase() + " = {"); lines.add("\t\tkdc = " + domain); lines.add("\t\tadmin_server = " + domain); lines.add("\t}"); FileWriter writer = null;/* w ww . j a va 2 s . co m*/ try { writer = new FileWriter(tempFile); IOUtils.writeLines(lines, System.lineSeparator(), writer); } finally { if (writer != null) { // IOUtils.closeQuietly(writer); safeClose(writer); } } return tempFile; }
From source file:io.cloudslang.content.httpclient.build.auth.AuthSchemeProviderLookupBuilder.java
private static File createLoginConfig() throws IOException { File tempFile = File.createTempFile("krb", "loginConf"); tempFile.deleteOnExit(); ArrayList<String> lines = new ArrayList<>(); lines.add("com.sun.security.jgss.initiate {\n" + " " + KrbHttpLoginModule.class.getCanonicalName() + " required\n" + " doNotPrompt=true\n" + " useFirstPass=true\n" + " debug=true ;\n" + "};"); FileWriter writer = null;// w w w . j av a 2 s .c o m try { writer = new FileWriter(tempFile); IOUtils.writeLines(lines, System.lineSeparator(), writer); } finally { if (writer != null) { // IOUtils.closeQuietly(writer); safeClose(writer); } } return tempFile; }