List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:com.greenpepper.server.license.LicenceGenerator.java
private static void buildCommercial(int users, Date supportDate) throws Exception { File file = File.createTempFile("commercial", ".lic"); License license = License.commercial("My Paying Company", _2006, supportDate, users); LicenseManager lm = new LicenseManager(getLicenseParam()); lm.store(license, file);//from w w w. jav a2 s . c o m if (deleteFiles) file.deleteOnExit(); System.out.println( "# Commercial " + users + " USERS - Expery: " + new FormatedDate(supportDate).getFormatedDate()); System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file)))); System.out.println(""); }
From source file:com.creactiviti.piper.plugin.ffmpeg.Ffprobe.java
@Override public Map<String, Object> handle(Task aTask) throws Exception { CommandLine cmd = new CommandLine("ffprobe"); cmd.addArgument("-v").addArgument("quiet").addArgument("-print_format").addArgument("json") .addArgument("-show_error").addArgument("-show_format").addArgument("-show_streams") .addArgument(aTask.getRequiredString("input")); log.debug("{}", cmd); DefaultExecutor exec = new DefaultExecutor(); File tempFile = File.createTempFile("log", null); try (PrintStream stream = new PrintStream(tempFile);) { exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd);/*from w ww. ja va2 s.c o m*/ return parse(FileUtils.readFileToString(tempFile)); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(tempFile))); } finally { FileUtils.deleteQuietly(tempFile); } }
From source file:com.hp.alm.ali.idea.rest.TroubleShootServiceTest.java
@Test public void testRecording() throws IOException { File file = File.createTempFile("trouble", ""); ResultInfo resultInfo = ResultInfo.create(new ByteArrayOutputStream()); resultInfo.setLocation("location"); resultInfo.setHttpStatus(401);/*from w ww . j a v a2s . c o m*/ resultInfo.setReasonPhrase("failed1"); troubleShootService.loginFailure(1, new AuthenticationFailureException(resultInfo)); troubleShootService.request(getProject(), "GET", new MyInputData("<foo1/>"), "defects/{0}", "1"); MyResultInfo result = new MyResultInfo(); result.getOutputStream().write("foobar1".getBytes()); troubleShootService.response(1, 200, result); Assert.assertFalse(troubleShootService.isRunning()); troubleShootService.start(file); Assert.assertTrue(troubleShootService.isRunning()); resultInfo.setReasonPhrase("failed2"); troubleShootService.loginFailure(1, new AuthenticationFailureException(resultInfo)); troubleShootService.request(getProject(), "GET", new MyInputData("<foo2/>"), "defects/{0}", "2"); result = new MyResultInfo(); result.getHeaders().put("a", "b"); result.getOutputStream().write("foobar2".getBytes()); troubleShootService.response(1, 200, result); troubleShootService.stop(); Assert.assertFalse(troubleShootService.isRunning()); resultInfo.setReasonPhrase("failed3"); troubleShootService.loginFailure(1, new AuthenticationFailureException(resultInfo)); troubleShootService.request(getProject(), "GET", new MyInputData("<foo3/>"), "defects/{0}", "3"); result = new MyResultInfo(); result.getOutputStream().write("foobar3".getBytes()); troubleShootService.response(1, 200, result); String data = IOUtils.toString(new FileInputStream(file)); // not started Assert.assertFalse(data.contains("failed1")); Assert.assertFalse(data.contains(">>>>> GET defects/{0} [1]")); Assert.assertFalse(data.contains("foobar1")); // failure Assert.assertTrue(data.contains("<<<<< login failure: #1")); Assert.assertTrue(data.contains("<<<<< 401 failed2 [location: location]")); // request Assert.assertTrue(data.contains(">>>>> GET defects/{0} [2]")); // response Assert.assertTrue(data.contains(">>>>> data: <foo2/>")); Assert.assertTrue(data.contains("<<<<< status: 200")); Assert.assertTrue(data.contains("<<<<< headers: {a=b}")); Assert.assertTrue(data.contains("<<<<< data: foobar2")); // already stopped Assert.assertFalse(data.contains("failed3")); Assert.assertFalse(data.contains(">>>>> GET defects/{0} [3]")); Assert.assertFalse(data.contains("foobar3")); }
From source file:net.sourceforge.jukebox.model.SettingsTest.java
/** * Tests the <code>load</code> and <code>save</code> methods. * @throws IOException IOException/*from w ww .j a v a 2s.co m*/ * @throws ConfigurationException ConfigurationException */ @Test public final void testLoad() throws IOException, ConfigurationException { Settings settings = new Settings(); settings.setContentFolder("/var/media"); settings.setPlayerUrl("http://localhost/play"); settings.setModifiedDays(MODIFIED_DAYS); File file = File.createTempFile("dummy", "properties"); file.deleteOnExit(); PropertiesConfiguration configuration = new PropertiesConfiguration(file); settings.save(configuration); Settings savedSettings = new Settings(); savedSettings.load(configuration); assertEquals(settings, savedSettings); }
From source file:com.joyent.manta.client.AuthAwareConfigContextTest.java
public void canMonitorRelevantFieldsInConfig() throws IOException { final AuthAwareConfigContext authConfig = new AuthAwareConfigContext(config); final KeyPair currentKeyPair = authConfig.getKeyPair(); Assert.assertNotNull(currentKeyPair); // key file (move key content to a file) final File keyFile = File.createTempFile("private-key", ""); FileUtils.forceDeleteOnExit(keyFile); FileUtils.writeStringToFile(keyFile, authConfig.getPrivateKeyContent(), StandardCharsets.UTF_8); authConfig.setPrivateKeyContent(null); authConfig.setMantaKeyPath(keyFile.getAbsolutePath()); authConfig.reload();/*from w w w. j a va2 s . c om*/ differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair()); // key id authConfig.setMantaKeyId("MD5:" + KeyFingerprinter.md5Fingerprint(authConfig.getKeyPair())); authConfig.reload(); differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair()); // disable native signatures final ThreadLocalSigner currentSigner = authConfig.getSigner(); authConfig.setDisableNativeSignatures(true); authConfig.reload(); Assert.assertNotSame(currentSigner, authConfig.getSigner()); // disable auth entirely authConfig.setNoAuth(true); authConfig.reload(); Assert.assertNull(authConfig.getKeyPair()); }
From source file:com.openedit.util.FileUtils.java
/** * Create a temporary directory with a unique name beginning with the given * prefix./*from w ww.j ava2s.c o m*/ * * @param inPrefix * The prefix for the created directory * * @return DOCME * * @throws IOException * DOCME */ public File createTempDir(String inPrefix) throws IOException { File tempDir = File.createTempFile(inPrefix, null); tempDir.delete(); tempDir.mkdir(); return tempDir; }
From source file:com.wavemaker.tools.webapp.WebXmlSupportTest.java
public void testReadWrite() throws Exception { File f = new ClassPathResource("com/wavemaker/tools/webapp/" + ProjectConstants.WEB_XML).getFile(); assertTrue(f.exists());/* w ww.j av a 2 s.c o m*/ WebAppType wat = WebXmlSupport.readWebXml(new FileSystemResource(f)); for (Object o : wat.getDescriptionAndDisplayNameAndIcon()) { if (o instanceof DisplayNameType) { DisplayNameType dnt = (DisplayNameType) o; assertEquals("ActiveGrid Studio", dnt.getValue()); } else if (o instanceof ServletType) { ServletType st = (ServletType) o; assertEquals("springapp", st.getServletName().getValue()); } else { // System.out.println("o: "+o); } } File fp = File.createTempFile("TestWebXmlSupport_testReadWrite", ".xml"); fp.deleteOnExit(); try { OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(fp)); WebXmlSupport.writeWebXml(wat, osw); String fpContents = FileUtils.readFileToString(fp); assertTrue(fpContents.contains("ActiveGrid Studio")); assertTrue(fpContents.contains("springapp")); WebXmlSupport.readWebXml(new FileSystemResource(fp)); } finally { fp.delete(); } }
From source file:ijfx.core.workflow.WorkflowIOTest.java
@Test public void channelSettings() throws IOException { ChannelSettings channelSettings = new DefaultChannelSettings() .addSetting("GFP", 200, 400, new ColorTable8()).addSetting("mCherry", 100, 300, new ColorTable16()); File tmpFile = File.createTempFile("channelsettings", ".json"); ObjectMapper mapper = workflowIOService.getObjectMapper(); mapper.writeValue(tmpFile, channelSettings); displayFile(tmpFile);/* w w w .j av a 2 s.com*/ ChannelSettings loaded = mapper.readValue(tmpFile, ChannelSettings.class); Assert.assertNotNull(loaded); Assert.assertEquals("same number of channels", channelSettings.getChannelCount(), loaded.getChannelCount()); Assert.assertEquals("same channels", channelSettings.get(0).getChannelMin(), loaded.get(0).getChannelMin(), 0.0); System.out.println("Testing color tables..."); for (int i = 0; i != channelSettings.getChannelCount(); i++) { ColorTable c1 = channelSettings.get(i).getColorTable(); ColorTable c2 = loaded.get(i).getColorTable(); Assert.assertEquals("Channel length " + (i + 1), c1.getLength(), c2.getLength()); for (int j = 0; j != c1.getLength(); j++) { Assert.assertEquals(String.format("Byte from channel %d / %d", i, j), c1.get(0, j), c2.get(0, j)); } } //Assert.assertEquals("same colot table byes", channelSettings.get(0).getColorTable().); }
From source file:edu.umn.msi.tropix.common.test.FileUtilsTest.java
@BeforeMethod(groups = "unit") public void init() throws IOException { this.file = File.createTempFile("moo", "cow"); }
From source file:org.ocpsoft.redoculous.tests.git.DeleteAndReinitializeRepositoryTest.java
@Before public void before() throws IOException, GitAPIException { repository = File.createTempFile("redoc", "ulous-test"); repository.delete();/*from www . j a v a 2s. c o m*/ repository.mkdirs(); document = new File(repository, "document.asciidoc"); document.createNewFile(); Files.write(document, getClass().getClassLoader().getResourceAsStream("asciidoc/toc.asciidoc")); repo = Git.init().setDirectory(repository).call(); repo.add().addFilepattern("document.asciidoc").call(); repo.commit().setMessage("Initial commit.").call(); }