List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:com.github.cshubhamrao.MediaConverter.MainUI.java
/** * This is the main method for {@code MainUI} * * @param args the command line arguments */// www . j a va2 s . c om public static void main(String args[]) { try { logFile = File.createTempFile("MediaConverter", ".txt"); } catch (IOException ex) { Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex); } // Create the FFMpeg executable in %temp% on startup. new Thread(new FFMpegLoader()).start(); try { /* * Set the Nimbus look and feel */ for (javax.swing.UIManager.LookAndFeelInfo lafInfo : javax.swing.UIManager.getInstalledLookAndFeels()) { if (lafInfo.getName().equals("Nimbus")) { System.out.println(lafInfo.getName()); javax.swing.UIManager.setLookAndFeel(lafInfo.getClassName()); } else { // javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } /* * Create and display the form */ // FOR JDK 8 // java.awt.EventQueue.invokeLater(() -> {new MainUI().setVisible(true);}); //For JDK 7 java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new MainUI().setVisible(true); } }); }
From source file:io.cloudslang.content.database.services.SQLQueryLobService.java
public static boolean executeSqlQueryLob(SQLInputs sqlInputs) throws Exception { if (StringUtils.isEmpty(sqlInputs.getSqlCommand())) { throw new Exception("command input is empty."); }/*from www.j a v a2 s . c om*/ boolean isLOB = false; ConnectionService connectionService = new ConnectionService(); try (final Connection connection = connectionService.setUpConnection(sqlInputs)) { StringBuilder strColumns = new StringBuilder(sqlInputs.getStrColumns()); connection.setReadOnly(true); Statement statement = connection.createStatement(sqlInputs.getResultSetType(), sqlInputs.getResultSetConcurrency()); statement.setQueryTimeout(sqlInputs.getTimeout()); ResultSet results = statement.executeQuery(sqlInputs.getSqlCommand()); ResultSetMetaData mtd = results.getMetaData(); int iNumCols = mtd.getColumnCount(); for (int i = 1; i <= iNumCols; i++) { if (i > 1) strColumns.append(sqlInputs.getStrDelim()); strColumns.append(mtd.getColumnLabel(i)); } sqlInputs.setStrColumns(strColumns.toString()); int nr = -1; while (results.next()) { nr++; final StringBuilder strRowHolder = new StringBuilder(); for (int i = 1; i <= iNumCols; i++) { if (i > 1) strRowHolder.append(sqlInputs.getStrDelim()); Object columnObject = results.getObject(i); if (columnObject != null) { String value; if (columnObject instanceof java.sql.Clob) { isLOB = true; final File tmpFile = File.createTempFile("CLOB_" + mtd.getColumnLabel(i), ".txt"); copyInputStreamToFile( new ReaderInputStream(results.getCharacterStream(i), StandardCharsets.UTF_8), tmpFile); if (sqlInputs.getLRowsFiles().size() == nr) { sqlInputs.getLRowsFiles().add(nr, new ArrayList<String>()); sqlInputs.getLRowsNames().add(nr, new ArrayList<String>()); } sqlInputs.getLRowsFiles().get(nr).add(tmpFile.getAbsolutePath()); sqlInputs.getLRowsNames().get(nr).add(mtd.getColumnLabel(i)); value = "(CLOB)..."; } else { value = results.getString(i); if (sqlInputs.isNetcool()) value = SQLUtils.processNullTerminatedString(value); } strRowHolder.append(value); } else strRowHolder.append("null"); } sqlInputs.getLRows().add(strRowHolder.toString()); } } return isLOB; }
From source file:gov.nih.nci.cabig.caaers.rules.business.service.EvaluationServiceImplIntegrationTest.java
/** * Deployed rules :// w w w . j av a 2 s. com * Rule 1 - Grade >= and significance >= 0.8 NOTIFY * Rule 2 - Grade <= 1 DO_NOT_NOTIFY * Rule 3 - Grade == 3 and significance <= 0.3 DO_NOT_NOTIFY * @throws Exception */ public void testEvaluateSafetySignallingRules() throws Exception { InputStream in = RuleUtil.getResouceAsStream("safety_signalling_rules_study_7211.xml"); String xml = RuleUtil.getFileContext(in); System.out.println(xml); File f = File.createTempFile("r_" + System.currentTimeMillis(), "sae.xml"); System.out.println(f.getAbsolutePath()); FileWriter fw = new FileWriter(f); IOUtils.write(xml, fw); IOUtils.closeQuietly(fw); assertTrue(f.exists()); assertTrue(findRuleSets().isEmpty()); caaersRulesEngineService.importRules(f.getAbsolutePath()); f.delete(); List<RuleSet> ruleSets = findRuleSets(); assertFalse(ruleSets.isEmpty()); RuleSet rs = ruleSets.get(0); assertTrue(rs.isEnabled()); TreatmentAssignment ta = Fixtures.createTreatmentAssignment(); Study s = Fixtures.createStudy("x"); s.setId(2); s.addTreatmentAssignment(ta); //Rule 1 - Grade >= and significance >= 0.8 NOTIFY { ObservedAdverseEventProfile observedAE1 = new ObservedAdverseEventProfile(); observedAE1.setLowLevelTerm(Fixtures.createLowLevelTerm("abcd", "efg")); observedAE1.setGrade(Grade.LIFE_THREATENING); observedAE1.setObservedSignificance(0.9); observedAE1.setpValue(0.9); observedAE1.setTreatmentAssignment(ta); SafetyRuleEvaluationResultDTO result = evaluationService.evaluateSafetySignallingRules(observedAE1); assertEquals("Rule-1", result.getRulesMatched().get(0)); assertEquals(NotificationStatus.NOTIFY, result.getNotificationStatus()); } //Rule 1 - Grade >= and significance >= 0.8 NOTIFY { ObservedAdverseEventProfile observedAE1 = new ObservedAdverseEventProfile(); observedAE1.setLowLevelTerm(Fixtures.createLowLevelTerm("abcd", "efg")); observedAE1.setGrade(Grade.SEVERE); observedAE1.setObservedSignificance(0.9); observedAE1.setpValue(0.9); observedAE1.setTreatmentAssignment(ta); SafetyRuleEvaluationResultDTO result = evaluationService.evaluateSafetySignallingRules(observedAE1); assertEquals("Rule-1", result.getRulesMatched().get(0)); assertEquals(NotificationStatus.NOTIFY, result.getNotificationStatus()); } //Rule 2 - Grade <= 1 DO_NOT_NOTIFY { ObservedAdverseEventProfile observedAE1 = new ObservedAdverseEventProfile(); observedAE1.setLowLevelTerm(Fixtures.createLowLevelTerm("abcd", "efg")); observedAE1.setGrade(Grade.NORMAL); observedAE1.setObservedSignificance(0.9); observedAE1.setpValue(0.9); observedAE1.setTreatmentAssignment(ta); SafetyRuleEvaluationResultDTO result = evaluationService.evaluateSafetySignallingRules(observedAE1); assertEquals("Rule-2", result.getRulesMatched().get(0)); assertEquals(NotificationStatus.DO_NOT_NOTIFY, result.getNotificationStatus()); } //Rule 3 - Grade == 3 and significance <= 0.3 DO_NOT_NOTIFY { ObservedAdverseEventProfile observedAE1 = new ObservedAdverseEventProfile(); observedAE1.setLowLevelTerm(Fixtures.createLowLevelTerm("abcd", "efg")); observedAE1.setGrade(Grade.SEVERE); observedAE1.setObservedSignificance(0.3); observedAE1.setpValue(0.3); observedAE1.setTreatmentAssignment(ta); SafetyRuleEvaluationResultDTO result = evaluationService.evaluateSafetySignallingRules(observedAE1); assertEquals("Rule-3", result.getRulesMatched().get(0)); assertEquals(NotificationStatus.DO_NOT_NOTIFY, result.getNotificationStatus()); } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.file.FileListTest.java
/** * @throws Exception if the test fails//w ww.j a v a2s . co m */ @Test @Alerts({ "1", "true" }) public void in() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head><title>foo</title>\n" + "<script>\n" + "function test() {\n" + " if (document.testForm.fileupload.files) {\n" + " var files = document.testForm.fileupload.files;\n" + " alert(files.length);\n" + " alert(0 in files);\n" + " }\n" + "}\n" + "</script>\n" + "</head>\n" + "<body>\n" + " <form name='testForm'>\n" + " <input type='file' id='fileupload' name='fileupload'>\n" + " </form>\n" + " <button id='testBtn' onclick='test()'>Tester</button>\n" + "</body>\n" + "</html>"; final WebDriver driver = loadPage2(html); final File tstFile = File.createTempFile("HtmlUnitUploadTest", ".txt"); try { FileUtils.writeStringToFile(tstFile, "Hello HtmlUnit", TextUtil.DEFAULT_CHARSET); final String path = tstFile.getCanonicalPath(); driver.findElement(By.name("fileupload")).sendKeys(path); driver.findElement(By.id("testBtn")).click(); verifyAlerts(driver, getExpectedAlerts()); } finally { FileUtils.deleteQuietly(tstFile); } }
From source file:com.cj.restspecs.mojo.Util.java
public static File tempDir() { try {/*from www .ja v a 2 s . c om*/ File path = File.createTempFile("tempdirectory", ".dir"); delete(path); mkdirs(path); return path; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.playonlinux.core.webservice.HTTPDownloaderTest.java
@Test public void testGet_DownloadFile_FileIsDownloaded() throws Exception { mockServer.when(request().withMethod("GET").withPath("/test.txt")).respond( response().withStatusCode(200).withHeaders(new Header("Content-Type", "application/config")) .withBody("Content file to download")); File temporaryFile = File.createTempFile("test", "txt"); temporaryFile.deleteOnExit();//from w w w .j a va 2s . c om new HTTPDownloader(mockServerURL).get(temporaryFile); String fileContent = IOUtils.toString(new FileReader(temporaryFile)); assertEquals("Content file to download", fileContent); }
From source file:com.legstar.protobuf.cobol.ProtoCobolUtilsTest.java
public void testExtractPackageNameExtraWhiteSpacesFromProtoFile() throws Exception { File protoFile = File.createTempFile(getName(), ".proto"); protoFile.deleteOnExit();//w ww .j a v a 2s. co m FileUtils.writeStringToFile(protoFile, "option java_package = \"com.example.tutorial\" ;"); ProtoFileJavaProperties javaProperties = ProtoCobolUtils.getJavaProperties(protoFile); assertEquals("com.example.tutorial", javaProperties.getJavaPackageName()); }
From source file:com.ikon.util.FileUtils.java
/** * Create temp file with extension from mime *///from www .j av a 2s . c o m public static File createTempFileFromMime(String mimeType) throws DatabaseException, IOException { MimeType mt = MimeTypeDAO.findByName(mimeType); String ext = mt.getExtensions().iterator().next(); return File.createTempFile("okm", "." + ext); }
From source file:be.fedict.eid.dss.client.LoggingSoapHandler.java
public boolean handleMessage(SOAPMessageContext context) { LOG.debug("handle message"); Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); LOG.debug("outbound message: " + outboundProperty); SOAPMessage soapMessage = context.getMessage(); ByteArrayOutputStream output = new ByteArrayOutputStream(); try {// w w w.j a v a 2s . c o m if (this.logToFile) { File tmpFile = File.createTempFile( "eid-dss-soap-" + (outboundProperty ? "outbound" : "inbound") + "-", ".xml"); FileOutputStream fileOutputStream = new FileOutputStream(tmpFile); soapMessage.writeTo(fileOutputStream); fileOutputStream.close(); LOG.debug("tmp file: " + tmpFile.getAbsolutePath()); } soapMessage.writeTo(output); } catch (Exception e) { LOG.error("SOAP error: " + e.getMessage()); } LOG.debug("SOAP message: " + output.toString()); return true; }
From source file:io.ingenieux.lambda.shell.LambdaShell.java
private static void runCommandArray(OutputStream os, String... args) throws Exception { PrintWriter pw = new PrintWriter(os, true); File tempPath = File.createTempFile("tmp-", ".sh"); IOUtils.write(StringUtils.join(args, " "), new FileOutputStream(tempPath)); List<String> processArgs = new ArrayList<>(Arrays.asList("/bin/bash", "-x", tempPath.getAbsolutePath())); ProcessBuilder psBuilder = new ProcessBuilder(processArgs).// redirectErrorStream(true);// final Process process = psBuilder.start(); final Thread t = new Thread(() -> { try {/*from w w w . ja v a 2s .c o m*/ IOUtils.copy(process.getInputStream(), os); } catch (IOException e) { throw new RuntimeException(e); } }); t.start(); process.waitFor(); t.join(); int resultCode = process.exitValue(); }