List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:com.amazonaws.auth.profile.ProfilesConfigFileWriterTest.java
@Test public void testDumpToFile() throws IOException { File tmpFile = File.createTempFile("credentials.", null); Profile[] abcd = { new Profile("a", basicCredA), new Profile("b", basicCredB), new Profile("c", sessionCredC), new Profile("d", sessionCredD) }; ProfilesConfigFileWriter.dumpToFile(tmpFile, true, abcd); checkCredentialsFile(tmpFile, abcd); // Rewrite the file with overwrite=true Profile[] a = { new Profile("a", basicCredA) }; ProfilesConfigFileWriter.dumpToFile(tmpFile, true, a); checkCredentialsFile(tmpFile, a);/*from w ww . ja v a 2 s .c o m*/ // Rewrite the file with overwrite=false is not allowed try { ProfilesConfigFileWriter.dumpToFile(tmpFile, false, new Profile("a", basicCredA)); fail("Should have thrown exception since the destination file already exists."); } catch (AmazonClientException expected) { } }
From source file:au.org.ala.delta.editor.slotfile.model.SlotFileRepositoryTest.java
/** * Makes a copy of the supplied DELTA file and returns a new File created from the copied file. * @param fileName the ClassLoader relative name of the DELTA file. * @return a new File./*ww w .j a v a 2 s. com*/ * @throws IOException if the file cannot be found. */ private File copyToTemp(String fileName) throws IOException { URL deltaFileUrl = getClass().getResource(fileName); File tempDeltaFile = File.createTempFile("SlotFileRepositoryTest", ".dlt"); FileUtils.copyURLToFile(deltaFileUrl, tempDeltaFile); tempDeltaFile.deleteOnExit(); return tempDeltaFile; }
From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.FilenameChoiceListProviderSimpleTest.java
private File createTempDir() throws IOException { File tempFile = File.createTempFile("test", null); tempFile.delete();/*www .j a v a 2s .co m*/ tempFile.mkdir(); return tempFile; }
From source file:$.MyMapping.java
private String flux(File file, String pid) throws URISyntaxException, IOException, RecognitionException { File outfile = File.createTempFile("lobid", "rdf"); outfile.deleteOnExit();/*from w w w .j a va2s .c o m*/ File fluxFile = createFile("my-xmetadissplus-to-lobid.flux", "/tmp/my-xmetadissplus-to-lobid.flux"); createFile("my-xmetadissplus-to-lobid.xml", "/tmp/my-xmetadissplus-to-lobid.xml"); Flux.main(new String[] { fluxFile.getAbsolutePath(), "in=" + file.getAbsolutePath(), "out=" + outfile.getAbsolutePath(), "subject=" + pid }); return FileUtils.readFileToString(outfile).trim(); }
From source file:com.twitter.heron.common.config.ConfigReaderTest.java
@Test public void testLoadFile() throws IOException { InputStream inputStream = loadResource(); File file = File.createTempFile("defaults_temp", "yaml"); file.deleteOnExit();/*from w w w .j a v a 2 s . c o m*/ OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); outputStream.close(); Map<String, Object> props = ConfigReader.loadFile(file.getAbsolutePath()); testProperty(props); }
From source file:it.unitn.elisco.servlet.ImageUploadServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from www.j a v a 2s . c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); Person user; if (request.getRequestURI().equals("/admin/image_upload")) { user = (Person) session.getAttribute("admin"); } else { user = (Person) session.getAttribute("student"); } // Get the image uploaded by the user as a stream Part imagePart = request.getPart("image"); String imageExtension = "." + imagePart.getSubmittedFileName().split("\\.")[1]; // Write to a temp file File tempFile = File.createTempFile("tmp", imageExtension); tempFile.deleteOnExit(); FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copy(imagePart.getInputStream(), out); // Upload the image to Cloudinary ImageUploader uploader = ImageUploader.getInstance(); String imageId = uploader.uploadImageToCloud(user, tempFile); // Get the url for the uploaded image String imageUrl = uploader.getURLWithDimensions(imageId, 200, 200); // Send JSON response back to ajax String json = new Gson().toJson(imageUrl); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json); }
From source file:de.tudarmstadt.ukp.uby.ubycreate.WordNetCreator.java
/** * This method converts wordNet into ubyXML,stores it into a temporary file * and then migrates the data from the temporary file into DB * *//*ww w .j a v a 2s . com*/ @Override public void lexicon2DB(final DBConfig dbConfig, String source) throws IOException, XMLStreamException, SAXException, DocumentException, JWNLException { String lexicalName = "WordNet"; File lmfXML = File.createTempFile("tempfile", ".tmp"); lmfXML = lexicon2XML(source, lmfXML); /* Persisting lmfXML into DB */ XMLToDBTransformer xmlToDB = new XMLToDBTransformer(dbConfig); xmlToDB.transform(lmfXML, lexicalName); System.out.println("DB Operation DONE"); lmfXML.deleteOnExit(); }
From source file:org.ocpsoft.redoculous.tests.markdown.MarkdownRenderTest.java
@Before public void before() throws IOException, GitAPIException { repository = File.createTempFile("redoc", "ulous-test"); repository.delete();// ww w . j a v a 2 s . c o m repository.mkdirs(); File document = new File(repository, "document.markdown"); document.createNewFile(); Files.write(document, getClass().getClassLoader().getResourceAsStream("markdown/document.markdown")); Git repo = Git.init().setDirectory(repository).call(); repo.add().addFilepattern("document.markdown").call(); repo.commit().setMessage("Initial commit.").call(); }
From source file:com.joyent.manta.config.ConfigContextTest.java
public void canValidateContextWithKeyPaths() throws IOException { File mantaAuthPrivateKey = File.createTempFile("manta-key", ""); FileUtils.forceDeleteOnExit(mantaAuthPrivateKey); FileUtils.write(mantaAuthPrivateKey, UnitTestConstants.PRIVATE_KEY, StandardCharsets.US_ASCII); File encryptionPrivateKey = File.createTempFile("encryption-key", ""); FileUtils.forceDeleteOnExit(encryptionPrivateKey); FileUtils.writeByteArrayToFile(encryptionPrivateKey, keyBytes); StandardConfigContext config = new StandardConfigContext(); config.setMantaURL(DefaultsConfigContext.DEFAULT_MANTA_URL); config.setMantaUser("username"); config.setMantaKeyId(UnitTestConstants.FINGERPRINT); config.setMantaKeyPath(mantaAuthPrivateKey.getAbsolutePath()); config.setClientEncryptionEnabled(true); config.setEncryptionKeyId("test-key-1"); config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.DEFAULT_MODE); config.setPermitUnencryptedDownloads(false); config.setEncryptionPrivateKeyPath(encryptionPrivateKey.getAbsolutePath()); config.setEncryptionAlgorithm(AesGcmCipherDetails.INSTANCE_128_BIT.getCipherId()); ConfigContext.validate(config);// w w w.ja v a 2 s . c om }