Example usage for java.io PrintStream print

List of usage examples for java.io PrintStream print

Introduction

In this page you can find the example usage for java.io PrintStream print.

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:org.apache.bookkeeper.tools.framework.CommandUtils.java

public static void printUsage(PrintStream printer, String usage) {
    final int indent = ((USAGE_HEADER.length() / DEFAULT_INDENT) + 1) * DEFAULT_INDENT;
    final int firstIndent = indent - USAGE_HEADER.length();
    printer.print(USAGE_HEADER);
    printDescription(printer, firstIndent, indent, usage);
    printer.println();//  w  w w .j a va  2s. c om
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileProtection.java

/**
 * Saves the message digest file in a format compatible with {@code md5sum}.
 * /*  w ww.  j a  va  2s . co m*/
 * @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:esiptestbed.mudrod.ontology.process.LocalOntology.java

protected static void renderRestriction(PrintStream out, Restriction r) {
    if (!r.isAnon()) {
        out.print("Restriction ");
        renderURI(out, r.getModel(), r.getURI());
    } else {//from  w  w w .  j  a  v  a2s.c o  m
        renderAnonymous(out, r, "restriction");
    }

    out.print(" on property ");
    renderURI(out, r.getModel(), r.getOnProperty().getURI());
}

From source file:esiptestbed.mudrod.ontology.process.LocalOntology.java

protected static void indent(PrintStream out, int depth) {
    for (int i = 0; i < depth; i++) {
        out.print(" ");
    }//from   www  .ja v a  2  s .  c  o m
}

From source file:edu.stanford.muse.graph.directed.Digraph.java

/** input is a set of docid -> terms in the doc map 
 * @throws FileNotFoundException */
public static void doIt(Map<Integer, Collection<Collection<String>>> docMap, String outfile)
        throws FileNotFoundException {
    // index stores for each term, count of how many times it co-occurs with another in a doc.
    Map<String, Map<String, Integer>> index = new LinkedHashMap<String, Map<String, Integer>>();
    Map<String, Integer> termFreq = new LinkedHashMap<String, Integer>();

    // compute index
    for (Integer num : docMap.keySet()) {
        Collection<Collection<String>> paras = docMap.get(num);

        for (Collection<String> paraNames : paras) {
            System.out.println(num + ". " + paraNames.size() + " names " + " prev index size " + index.size()
                    + " term freq size " + termFreq.size());
            if (paraNames.size() > 100) {
                log.warn("skipping long para" + paraNames);
                continue;
            }/*  w ww  .  j a  v  a  2s .co  m*/

            for (String s : paraNames) {
                s = s.toLowerCase();
                // bump up term freq for this term
                Integer X = termFreq.get(s);
                termFreq.put(s, (X == null) ? 1 : X + 1);

                // bump up counts for co-occurring terms... 
                // unfortunately n^2 operation here
                for (String s1 : paraNames) {
                    if (s == s1)
                        continue;

                    Map<String, Integer> termMap = index.get(s);
                    if (termMap == null) {
                        // allocate termMap if this is the first time we've seen s
                        termMap = new LinkedHashMap<String, Integer>(1);
                        index.put(s, termMap);
                    }

                    // bump the count
                    Integer I = termMap.get(s1);
                    termMap.put(s1, (I == null) ? 1 : I + 1);
                }
            }
        }
    }

    // process index and store it as a graph structure

    Digraph<String> graph = new Digraph<String>();
    for (String term : index.keySet()) {
        Map<String, Integer> map = index.get(term);
        if (map == null) {
            // no edges, just add it to the graph and continue
            graph.add(term);
            continue;
        }

        // compute total co-occurrence across all other terms this term is associated with
        int total = 0;
        for (Integer x : map.values())
            total += x;
        // proportionately allocate weight
        for (String x : map.keySet())
            graph.addEdge(term, x, ((float) map.get(x)));
        //      graph.addEdge(term, x, ((float) map.get(x))/total);
    }
    String s = graph.dump();
    PrintStream pw = new PrintStream(new FileOutputStream(outfile));
    pw.print(s);
    pw.close();
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.Timing.java

/**
 * Prints the relative magnitudes of the collected timer data to the
 * specified {@link PrintStream}.//from   w w  w .  j a  v a 2  s .c  o  m
 * 
 * @param out the stream to which data is printed
 */
public static void printMagnitudes(PrintStream out) {
    double min = Double.POSITIVE_INFINITY;

    for (Map.Entry<String, SummaryStatistics> entry : data.entrySet()) {
        min = Math.min(min, entry.getValue().getMean());
    }

    for (Map.Entry<String, SummaryStatistics> entry : data.entrySet()) {
        out.print(entry.getKey());
        out.print(": ");
        out.print(entry.getValue().getMean() / min);
        out.println();
    }
}

From source file:fr.in2p3.maven.plugin.DependencyXmlMojo.java

private static void addAttribute(PrintStream out, String name, String value) {
    if (value != null) {
        if (value.contains("\"")) {
            value = value.replaceAll("\"", "'");
        }//w w  w  . j a  va 2 s .  c o  m
        out.print(" " + name + "=\"" + StringEscapeUtils.escapeHtml4(value) + "\"");
    }
}

From source file:fr.cs.examples.bodies.DEFile.java

private static void displayUsage(final PrintStream stream) {
    stream.print("usage: java DEFile");
    stream.print(" -in filename");
    stream.print(" [-help]");
    stream.print(" [-constant name]");
    stream.print(" [-all-constants]");
    stream.print(" [-start date]");
    stream.print(" [-end date]");
    stream.print(" [-out filename]");
    stream.println();//  www  . j  av a2  s.c o  m
}

From source file:org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator.java

private static void doExec(ExecWatch watch, PrintStream out, String... statements) {
    try {/*from   ww  w  .  j ava 2  s .  c  om*/
        out.print("Executing command: ");
        StringBuilder sb = new StringBuilder();
        for (String stmt : statements) {
            String s = String.format("\"%s\" ", stmt);
            sb.append(s);
            out.print(s);
            watch.getInput().write(s.getBytes(StandardCharsets.UTF_8));
        }
        sb.append(NEWLINE);
        out.println();
        watch.getInput().write(NEWLINE.getBytes(StandardCharsets.UTF_8));

        // get the command exit code and print it padded so it is easier to parse in ConatinerExecProc
        // We need to exit so that we know when the command has finished.
        sb.append(ExitCodeOutputStream.EXIT_COMMAND);
        out.print(ExitCodeOutputStream.EXIT_COMMAND);
        LOGGER.log(Level.FINEST, "Executing command: {0}", sb.toString());
        watch.getInput().write(ExitCodeOutputStream.EXIT_COMMAND.getBytes(StandardCharsets.UTF_8));

        out.flush();
        watch.getInput().flush();
    } catch (IOException e) {
        e.printStackTrace(out);
        throw new RuntimeException(e);
    }
}

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);/*from  ww w .j a va  2  s  . c om*/
    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;
}