List of usage examples for java.io PrintStream close
public void close()
From source file:com.runwaysdk.browser.JavascriptTestRunner.java
public static Test suite() throws Exception { // Read project.version Properties prop1 = new Properties(); ClassLoader loader1 = Thread.currentThread().getContextClassLoader(); InputStream stream1 = loader1.getResourceAsStream("avail-maven.properties"); prop1.load(stream1);// ww w. j a va 2s .co m String projVer = prop1.getProperty("mvn.project.version"); TestSuite suite = new TestSuite(); int browserLoopIterationNumber = 0; System.out.println("Preparing to run cross-browser javascript unit tests."); long totalTime = System.currentTimeMillis(); for (String browser : supportedBrowsers) { try { String browserDisplayName = String.valueOf(browser.charAt(1)).toUpperCase() + browser.substring(2); System.out.println("Opening " + browserDisplayName); TestSuite browserSuite = new TestSuite(browserDisplayName); selenium = new DefaultSelenium("localhost", 4444, browser, "http://localhost:8080/runwaysdk-browser-test-" + projVer + "/"); selenium.start(); isSeleniumStarted = true; selenium.open("MasterTestLauncher.jsp"); // selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('all');", "6000"); selenium.setTimeout("1000"); System.out.println("Running tests..."); long time = System.currentTimeMillis(); selenium.click("all"); selenium.waitForCondition( "!selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.isRunning()", Integer.toString(MAXIMUM_TOTAL_TEST_DURATION * 1000)); time = System.currentTimeMillis() - time; // elapsed time in milis if (time < 1000) { System.out.println("Tests completed in " + time + " miliseconds."); } else if (time < 60000) { time = time / 1000; System.out.println("Tests completed in " + time + " seconds."); } else if (time < 3600000) { time = time / (1000 * 60); System.out.println("Tests completed in " + time + " minutes."); } else { time = time / (1000 * 60 * 60); System.out.println("Tests completed in " + time + " hours."); } //System.out.println(selenium.getEval("\n\n" + "selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.getResults(selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Format.XML);") + "\n\n"); // tests are done running, get the results and display them through junit DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); String resultsJunitXML = selenium.getEval( "selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.getResults(selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Format.JUnitXML);"); String resultsYUITestXML = selenium.getEval( "selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.getResults(selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Format.XML);"); // Write the test output to xml Properties prop = new Properties(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); InputStream stream = loader.getResourceAsStream("default/common/terraframe.properties"); prop.load(stream); String basedir = prop.getProperty("local.root"); System.out.println("Writing javascript test results to '" + basedir + "/target/surefire-reports/TEST-com.runwaysdk.browser.JavascriptTestRunner-" + browserDisplayName + ".xml."); File dir = new File(basedir + "/target/surefire-reports"); dir.mkdirs(); final OutputStream os = new FileOutputStream(dir.getAbsolutePath() + "/TEST-com.runwaysdk.browser.JavascriptTestRunner-" + browserDisplayName + ".xml", false); final PrintStream printStream = new PrintStream(os); printStream.print(resultsJunitXML); printStream.close(); InputSource in = new InputSource(); in.setCharacterStream(new StringReader(resultsYUITestXML)); Element doc = db.parse(in).getDocumentElement(); NodeList suiteList = doc.getElementsByTagName("testsuite"); if (suiteList == null || suiteList.getLength() == 0) { //suiteList = (NodeList)doc; throw new Exception("Unable to find any suites!"); } String uniqueWhitespace = ""; for (int j = 0; j < browserLoopIterationNumber; j++) { uniqueWhitespace = uniqueWhitespace + " "; } for (int i = 0; i < suiteList.getLength(); i++) //looping through test suites { Node n = suiteList.item(i); TestSuite s = new TestSuite(); NamedNodeMap nAttrMap = n.getAttributes(); s.setName(nAttrMap.getNamedItem("name").getNodeValue() + uniqueWhitespace); NodeList testCaseList = ((Element) n).getElementsByTagName("testcase"); for (int j = 0; j < testCaseList.getLength(); j++) // looping through test cases { Node x = testCaseList.item(j); NamedNodeMap xAttrMap = x.getAttributes(); TestSuite testCaseSuite = new TestSuite(); testCaseSuite.setName(xAttrMap.getNamedItem("name").getNodeValue() + uniqueWhitespace); NodeList testList = ((Element) x).getElementsByTagName("test"); for (int k = 0; k < testList.getLength(); k++) // looping through tests { Node testNode = testList.item(k); NamedNodeMap testAttrMap = testNode.getAttributes(); Test t = new GeneratedTest( testAttrMap.getNamedItem("name").getNodeValue() + uniqueWhitespace); if (testAttrMap.getNamedItem("result").getNodeValue().equals("fail")) { ((GeneratedTest) t).testFailMessage = testAttrMap.getNamedItem("message") .getNodeValue(); } testCaseSuite.addTest(t); } s.addTest(testCaseSuite); } browserSuite.addTest(s); } //suite.addTest(browserSuite); browserLoopIterationNumber++; } // end try catch (Exception e) { throw (e); } finally { if (isSeleniumStarted) { selenium.stop(); isSeleniumStarted = false; } } } // end for loop on browsers totalTime = System.currentTimeMillis() - totalTime; // elapsed time in milis if (totalTime < 1000) { System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " miliseconds."); } else if (totalTime < 60000) { totalTime = totalTime / 1000; System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " seconds."); } else if (totalTime < 3600000) { totalTime = totalTime / (1000 * 60); System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " minutes."); } else { totalTime = totalTime / (1000 * 60 * 60); System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " hours."); } return suite; }
From source file:Main.java
private static void destroyPid(int pid) { Process suProcess = null;//from www .j a v a 2 s .c o m PrintStream outputStream = null; try { suProcess = Runtime.getRuntime().exec("su"); outputStream = new PrintStream(new BufferedOutputStream(suProcess.getOutputStream(), 8192)); outputStream.println("kill " + pid); outputStream.println("exit"); outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (outputStream != null) { outputStream.close(); } if (suProcess != null) { try { suProcess.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } } } }
From source file:com.intel.hadoop.hbase.dot.TestHiveIntegration.java
@BeforeClass public static void setUp() throws Exception { Configuration config = TEST_UTIL.getConfiguration(); config.set("hbase.coprocessor.region.classes", "com.intel.hadoop.hbase.dot.access.DataManipulationOps"); config.set("hbase.coprocessor.master.classes", "com.intel.hadoop.hbase.dot.access.DataDefinitionOps"); TEST_UTIL.startMiniCluster(1);//from w w w .j a v a 2 s.c o m TEST_UTIL.startMiniMapReduceCluster(); initialize(TEST_UTIL.getConfiguration()); // 1. To put the test data onto miniDFS, and get the file path FileSystem fs = FileSystem.get(config); FSDataOutputStream output = fs.create(new Path("/tsvfile")); PrintStream out = new PrintStream(output); out.println("row1|row1_fd1|row1_fd2|row1_fd3|row1_fd4"); out.println("row2|row2_fd1|row2_fd2|row2_fd3|row2_fd4"); out.println("row3|row3_fd1|row3_fd2|row3_fd3|row3_fd4"); out.println("row4|row4_fd1|row4_fd2|row4_fd3|row4_fd4"); out.println("row5|row5_fd1|row5_fd2|row5_fd3|row5_fd4"); out.close(); output.close(); // fs.copyFromLocalFile(new Path("./src/test/data/data"), new // Path("/tsvfile")); assertEquals("tsv file name is not correct", fs.listStatus(new Path("/tsvfile"))[0].getPath().getName(), "tsvfile"); }
From source file:Main.java
private static List<Integer> getAllRelatedPids(final int pid) { List<Integer> result = new ArrayList<Integer>(Arrays.asList(pid)); // use 'ps' to get this pid and all pids that are related to it (e.g. // spawned by it) try {/*from w w w . jav a 2 s . c o m*/ final Process suProcess = Runtime.getRuntime().exec("su"); new Thread(new Runnable() { @Override public void run() { PrintStream outputStream = null; try { outputStream = new PrintStream(new BufferedOutputStream(suProcess.getOutputStream(), 8192)); outputStream.println("ps"); outputStream.println("exit"); outputStream.flush(); } finally { if (outputStream != null) { outputStream.close(); } } } }).run(); if (suProcess != null) { try { suProcess.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } } BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new InputStreamReader(suProcess.getInputStream()), 8192); while (bufferedReader.ready()) { String[] line = SPACES_PATTERN.split(bufferedReader.readLine()); if (line.length >= 3) { try { if (pid == Integer.parseInt(line[2])) { result.add(Integer.parseInt(line[1])); } } catch (NumberFormatException ignore) { } } } } finally { if (bufferedReader != null) { bufferedReader.close(); } } } catch (IOException e1) { e1.printStackTrace(); } return result; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileProtection.java
/** * Saves the message digest file in a format compatible with {@code md5sum}. * //from ww w . j a va 2s. c om * @param file the file to be validated * @param digest the message digest * @throws IOException if an I/O error occurred */ private static void saveDigest(File file, byte[] digest) throws IOException { PrintStream ps = null; try { ps = new PrintStream(getDigestFile(file)); ps.print(Hex.encodeHex(digest)); ps.print(" "); ps.print(file.getPath()); } finally { if (ps != null) { ps.close(); } } }
From source file:org.apache.hadoop.hbase.TestClassFinder.java
/** * Compiles the test class with bogus code into a .class file. * Unfortunately it's very tedious.// w w w .j a v a 2 s . c o m * @param counter Unique test counter. * @param packageNameSuffix Package name suffix (e.g. ".suffix") for nesting, or "". * @return The resulting .class file and the location in jar it is supposed to go to. */ private static FileAndPath compileTestClass(long counter, String packageNameSuffix, String classNamePrefix) throws Exception { classNamePrefix = classNamePrefix + counter; String packageName = makePackageName(packageNameSuffix, counter); String javaPath = basePath + classNamePrefix + ".java"; String classPath = basePath + classNamePrefix + ".class"; PrintStream source = new PrintStream(javaPath); source.println("package " + packageName + ";"); source.println("public class " + classNamePrefix + " { public static void main(String[] args) { } };"); source.close(); JavaCompiler jc = ToolProvider.getSystemJavaCompiler(); int result = jc.run(null, null, null, javaPath); assertEquals(0, result); File classFile = new File(classPath); assertTrue(classFile.exists()); return new FileAndPath(packageName.replace('.', '/') + '/', classFile); }
From source file:Main.java
public static String toString(Document document) { PrintStream out = null; try {// w ww.j a va 2 s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); out = new PrintStream(baos); print(out, document); return new String(baos.toByteArray(), "UTF-8"); } catch (Exception ex) { // ignore } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } return null; }
From source file:Main.java
public static void save(String filename, Node node) throws IOException { PrintStream out = null; try {// w ww. j a v a 2 s . com out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8"); print(out, node); } catch (Exception ex) { throw new IOException(ex.getLocalizedMessage()); } finally { if (out != null) try { out.close(); } catch (Exception e) { // ignore } } }
From source file:it.mb.whatshare.PairOutboundActivity.java
/** * Saves the argument <tt>device</tt> as the (only) configured outbound * device.// ww w. j ava 2 s .co m * * <p> * If <tt>device</tt> is <code>null</code>, the currently configured device * is deleted. * * @param device * the device to be stored, or <code>null</code> if the current * association must be discarded * @param context * the application's context (used to open the association file * with) * @throws IOException * in case something is wrong with the file * @throws JSONException * in case something is wrong with the argument <tt>device</tt> */ public static void savePairing(PairedDevice device, Context context) throws IOException, JSONException { if (device == null) { Utils.debug("deleting outbound device... %s", context.deleteFile(PAIRING_FILE_NAME) ? "success" : "fail"); } else { FileOutputStream fos = context.openFileOutput(PAIRING_FILE_NAME, Context.MODE_PRIVATE); // @formatter:off JSONObject json = new JSONObject().put("name", device.name).put("type", device.type).put("assignedID", device.id); // @formatter:on PrintStream writer = new PrintStream(fos); writer.append(json.toString()); writer.flush(); writer.close(); } }
From source file:de.uni.bremen.monty.moco.Main.java
private static void writeAssembly(String outputFileName, String inputFileName, String llvmCode) throws IOException { PrintStream assemblyStream = null; if (outputFileName != null) { assemblyStream = new PrintStream(outputFileName); } else if (inputFileName != null) { assemblyStream = new PrintStream(FilenameUtils.removeExtension(inputFileName) + ".ll"); } else {/*from w w w .j a v a 2 s.c o m*/ assemblyStream = new PrintStream("output.ll"); } assemblyStream.print(llvmCode); assemblyStream.close(); }