List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:name.martingeisse.esdk.simulation.lwjgl.NativeLibraryHelper.java
/** * Extracts LWJGL libraries to a folder and * @throws Exception on errors/* ww w .j a va 2 s . c o m*/ */ public static void prepareNativeLibraries() throws Exception { // Unfortunately, Java is also too stupid to create a temp directory... tempFolder = File.createTempFile("miner-launcher-", ""); deleteRecursively(tempFolder); tempFolder.mkdir(); logger.debug("temp: " + tempFolder.getAbsolutePath()); // detect which set of native libraries to load, then extract the files resourcePath = OperatingSystemSelector.getHostOs().getNativeLibraryPath(); logger.debug("native library path: " + resourcePath); for (String fileName : OperatingSystemSelector.getHostOs().getNativeLibraryFileNames()) { extractFile(fileName); } // make Java use our libraries System.setProperty("java.library.path", tempFolder.getAbsolutePath()); final Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); fieldSysPath.setAccessible(true); fieldSysPath.set(null, null); }
From source file:QRCode.java
public static String createQRCode(String arg) { int size = 125; String fileType = "png"; File myFile = null;// www . j av a 2 s .co m UUID uuid = UUID.nameUUIDFromBytes(arg.getBytes()); try { myFile = File.createTempFile("temp-file-name", ".png"); Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix byteMatrix = qrCodeWriter.encode(uuid.toString(), BarcodeFormat.QR_CODE, size, size, hintMap); int CrunchifyWidth = byteMatrix.getWidth(); BufferedImage image = new BufferedImage(CrunchifyWidth, CrunchifyWidth, BufferedImage.TYPE_INT_RGB); image.createGraphics(); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, CrunchifyWidth, CrunchifyWidth); graphics.setColor(Color.BLACK); for (int i = 0; i < CrunchifyWidth; i++) { for (int j = 0; j < CrunchifyWidth; j++) { if (byteMatrix.get(i, j)) { graphics.fillRect(i, j, 1, 1); } } } ImageIO.write(image, fileType, myFile); //System.out.println("\n\nYou have successfully created QR Code " + myFile.getCanonicalPath()); return myFile.getCanonicalPath(); } catch (WriterException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:de.elomagic.mag.ConfigurationTest.java
@BeforeClass public static void beforeClassConfigurationTest() throws Exception { file = File.createTempFile("test_", ".properties"); file.deleteOnExit();/*from ww w . j ava 2 s .co m*/ }
From source file:Main.java
private static File createFileFromInputStream(InputStream inputStream, String name) { try {// w ww .j a va 2 s . c o m File f = File.createTempFile("font", null); OutputStream outputStream = new FileOutputStream(f); byte buffer[] = new byte[1024]; int length = 0; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } outputStream.close(); inputStream.close(); return f; } catch (Exception e) { // Logging exception e.printStackTrace(); } return null; }
From source file:com.googlecode.fannj.FannTest.java
public static File createTemp(File src) throws IOException { File temp = File.createTempFile("fannj_", ".net"); temp.deleteOnExit();//from w w w . j a v a2 s. c o m FileUtils.copyFile(src, temp); return temp; }
From source file:net.grinder.util.ConsolePropertiesFactory.java
/** * Create empty {@link ConsoleProperties}. the created {@link ConsoleProperties} instance links * with temp/temp_console directory.//w w w .j a v a2 s .c om * * @return empty {@link ConsoleProperties} instance */ public static ConsoleProperties createEmptyConsoleProperties() { File tmpFile = null; try { tmpFile = File.createTempFile("ngrinder", "tmp"); return new ConsoleProperties(SingleConsole.RESOURCE, tmpFile); } catch (Exception e) { throw processException("Exception occurred while creating empty console property", e); } finally { FileUtils.deleteQuietly(tmpFile); } }
From source file:Main.java
private static String createPKCS11ConfigFile(String pkcs11LibPath) { File f = null;//from w ww . j a v a 2s .com PrintWriter writer = null; try { f = File.createTempFile("pkcs11", ".cfg"); f.deleteOnExit(); writer = new PrintWriter(new FileOutputStream(f)); writer.println("name = verinice"); writer.println("description = verinice PKCS#11 configuration"); writer.println("library = " + pkcs11LibPath); writer.close(); } catch (IOException e) { return null; } finally { if (writer != null) writer.close(); } return f.getAbsolutePath(); }
From source file:com.linkedin.pinot.common.TestUtils.java
public static String getFileFromResourceUrl(URL resourceUrl) { System.out.println(resourceUrl); // Check if we need to extract the resource to a temporary directory String resourceUrlStr = resourceUrl.toString(); if (resourceUrlStr.contains("jar!")) { try {/*from ww w. ja v a2s. co m*/ String extension = resourceUrlStr.substring(resourceUrlStr.lastIndexOf('.')); File tempFile = File.createTempFile("pinot-test-temp", extension); LOGGER.info("Extractng from " + resourceUrlStr + " to " + tempFile.getAbsolutePath()); System.out.println("Extractng from " + resourceUrlStr + " to " + tempFile.getAbsolutePath()); FileUtils.copyURLToFile(resourceUrl, tempFile); return tempFile.getAbsolutePath(); } catch (IOException e) { throw new RuntimeException(e); } } else { System.out.println("Not extracting plain file " + resourceUrl); return resourceUrl.getFile(); } }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.annotations.Tools.java
public static String dumpCas(JCas jCas) { try {//from w w w. j a v a 2s . co m File f = File.createTempFile("casdump", ".txt"); SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(CasDumpWriter.class, CasDumpWriter.PARAM_OUTPUT_FILE, f)); StringBuilder result = new StringBuilder(FileUtils.readFileToString(f)); FileUtils.deleteQuietly(f); result.append("Id:").append(DocumentMetaData.get(jCas).getDocumentId()); return result.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.genericworkflownodes.knime.custom.ZipUtilsTest.java
public static File createTempDirectory() throws IOException { final File temp; temp = File.createTempFile("temp", Long.toString(System.nanoTime())); if (!(temp.delete())) { throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); }//from w w w .ja v a 2 s .co m if (!(temp.mkdir())) { throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); } return (temp); }