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.ctakes.ytex.kernel.metric.ConceptSimilarityServiceImpl.java

private static void printSimilarities(List<ConceptPair> conceptPairs,
        List<ConceptPairSimilarity> conceptSimList, List<SimilarityMetricEnum> metricList,
        List<SimilarityInfo> simInfos, boolean lcs, PrintStream os) {
    // print header
    os.print("Concept 1\tConcept 2");
    for (SimilarityMetricEnum metric : metricList) {
        os.print("\t");
        os.print(metric);/*from ww w.jav  a  2  s  .co m*/
    }
    if (lcs) {
        os.print("\tlcs(s)\tcorpus lcs\tintrinsic lcs\tpaths");
    }
    os.println();
    // print content
    for (ConceptPairSimilarity csim : conceptSimList) {
        ConceptPair p = csim.getConceptPair();
        os.print(p.getConcept1());
        os.print("\t");
        os.print(p.getConcept2());
        for (Double sim : csim.getSimilarities()) {
            os.print("\t");
            if (sim != null)
                os.print(String.format("%6f", sim));
            else
                os.print(0d);
        }
        if (lcs) {
            SimilarityInfo simInfo = csim.getSimilarityInfo();
            os.print("\t");
            Iterator<String> lcsIter = simInfo.getLcses().iterator();
            while (lcsIter.hasNext()) {
                os.print(lcsIter.next());
                if (lcsIter.hasNext())
                    os.print('|');
            }
            os.print("\t");
            os.print(simInfo.getCorpusLcs() == null ? "" : simInfo.getCorpusLcs());
            os.print("\t");
            os.print(simInfo.getIntrinsicLcs() == null ? "" : simInfo.getIntrinsicLcs());
            os.print("\t");
            os.print(formatPaths(simInfo.getLcsPaths()));
        }
        os.println();
    }
}

From source file:org.aspectj.testing.MakeTestClass.java

public void makeTestClass() throws Exception {
    FileOutputStream fos = new FileOutputStream(className + ".java");
    PrintStream out = new PrintStream(fos);
    out.print(HEADER);
    out.print(className);//from  w  ww. j a v a 2  s.com
    out.print(BODY_1);
    out.print(className);
    out.print(BODY_2);
    out.print(suiteFile);
    out.print(BODY_3);
    out.println();
    int testNo = 1;
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(3);
    for (AjcTest test : tests) {
        out.println();
        out.print("  public void test");
        out.print(nf.format(testNo++));
        out.println("(){");
        out.println("    runTest(\"" + test.getTitle() + "\");");
        out.println("  }");
    }
    out.println();
    out.println(FOOTER);
    out.close();
}

From source file:com.microsoft.tfs.client.clc.prompt.Prompt.java

/**
 * Reads a line from this command's {@link Input}.
 *
 * @param prompt/*from  w w w.  java2  s .  co m*/
 *        the line to print (without automatic newline) as the prompt the
 *        input (not null). Provide the full prompt string including any
 *        spaces or separators, for example:
 *
 *        <pre>
 *        &quot;Username: &quot;
 *        </pre>
 *
 * @param echo
 *        if true, what the user types is echoed. If false, it is not
 *        echoed.
 * @return the text the user typed, not including line endings, or null if
 *         an error occured writing the prompt or reading the input.
 */
public static String readLine(final Display display, final Input input, final String prompt,
        final boolean echo) {
    Check.notNull(prompt, "prompt"); //$NON-NLS-1$

    final PrintStream out = display.getPrintStream();
    if (out == null) {
        return null;
    }

    final InputStream in = input.getInputStream();
    if (in == null) {
        return null;
    }

    // Do not close this stream, we need to keep the InputStream open.
    final BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    String ret;
    try {
        if (echo == false) {
            if (ConsoleUtils.getInstance().disableEcho() == false) {
                display.printErrorLine(Messages.getString("Prompt.LocalEchoCouldNotBeDisabled")); //$NON-NLS-1$
            }
        }

        out.print(prompt);

        try {
            ret = reader.readLine();
        } catch (final IOException e) {
            /*
             * Don't log because it might contain sensitive information.
             */
            return null;
        }
    } finally {
        if (echo == false) {
            ConsoleUtils.getInstance().enableEcho();

            /*
             * Since echo was off, we didn't echo the user's newline, so
             * provide one here to even out the lines.
             */
            out.println();
        }

        /*
         * Note we don't close the BufferedReader because we need to keep
         * the input stream open for further processing
         */
    }

    return ret;
}

From source file:com.anrisoftware.mongoose.buildins.echobuildin.EchoBuildin.java

private OutputWorker createOutputNoNewLine() {
    return new OutputWorker() {

        @Override/* ww w.  jav  a  2 s  .  c o  m*/
        public void output(PrintStream output, String text) {
            output.print(text);
        }
    };
}

From source file:PatchyMIDlet.java

public void run() {
    try {/*from   www.  ja va 2s  . co  m*/
        mServerSocketConnection = (ServerSocketConnection) Connector.open("socket://:80");
        SocketConnection sc = null;
        while (mTrucking) {
            sc = (SocketConnection) mServerSocketConnection.acceptAndOpen();
            Reader in = new InputStreamReader(sc.openInputStream());

            PrintStream out = new PrintStream(sc.openOutputStream());
            out.print("HTTP/1.1 200 OK\r\n\r\n");
            out.print("Message");
            out.close();
            in.close();
            sc.close();
        }
    } catch (Exception e) {

    }
}

From source file:org.apache.hadoop.tracing.TraceAdmin.java

private void usage() {
    PrintStream err = System.err;
    err.print("Hadoop tracing configuration commands:\n"
            + "  -add [-class classname] [-Ckey=value] [-Ckey2=value2] ...\n"
            + "    Add a span receiver with the provided class name.  Configuration\n"
            + "    keys for the span receiver can be specified with the -C options.\n"
            + "    The span receiver will also inherit whatever configuration keys\n"
            + "    exist in the daemon's configuration.\n" + "  -help: Print this help message.\n"
            + "  -host [hostname:port]\n" + "    Specify the hostname and port of the daemon to examine.\n"
            + "    Required for all commands.\n" + "  -list: List the current span receivers.\n"
            + "  -remove [id]\n" + "    Remove the span receiver with the specified id.  Use -list to\n"
            + "    find the id of each receiver.\n");
}

From source file:org.ejbca.ui.web.RequestHelper.java

/**
 * Formats certificate in form to be received by IE
 *
 * @param bA input/*from  ww w .j  a va  2s .  c om*/
 * @param out Output
 */
public static void ieCertFormat(byte[] bA, PrintStream out) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bA)));
    int rowNr = 0;

    while (true) {
        String line = br.readLine();

        if (line == null) {
            break;
        }

        if (line.indexOf("END CERT") < 0) {
            if (line.indexOf(" CERT") < 0) {
                if (++rowNr > 1) {
                    out.println(" & _ ");
                } else {
                    out.print("    cert = ");
                }

                out.print('\"' + line + '\"');
            }
        } else {
            break;
        }
    }

    out.println();
}

From source file:hudson.console.AnnotatedLargeTextTest.java

@Test
public void smokes() throws Exception {
    ByteBuffer buf = new ByteBuffer();
    PrintStream ps = new PrintStream(buf, true);
    ps.print("Some text.\n");
    ps.print("Go back to " + TestNote.encodeTo("/root", "your home") + ".\n");
    ps.print("More text.\n");
    AnnotatedLargeText<Void> text = new AnnotatedLargeText<>(buf, Charsets.UTF_8, true, null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    text.writeLogTo(0, baos);//from  w  w  w . j  a  va2  s.c  o  m
    assertEquals("Some text.\nGo back to your home.\nMore text.\n", baos.toString());
    StringWriter w = new StringWriter();
    text.writeHtmlTo(0, w);
    assertEquals("Some text.\nGo back to <a href='/root'>your home</a>.\nMore text.\n", w.toString());
}

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

protected static void renderHierarchy(PrintStream out, OntClass cls, List occurs, int depth) {
    renderClassDescription(out, cls, depth);
    out.println();/*from  w ww.  j av  a 2s  .  c  om*/

    // recurse to the next level down
    if (cls.canAs(OntClass.class) && !occurs.contains(cls)) {
        for (Iterator i = cls.listSubClasses(true); i.hasNext();) {
            OntClass sub = (OntClass) i.next();

            // we push this expression on the occurs list before we recurse
            occurs.add(cls);
            renderHierarchy(out, sub, occurs, depth + 1);
            occurs.remove(cls);
        }
        for (Iterator i = cls.listInstances(); i.hasNext();) {
            Individual individual = (Individual) i.next();
            renderURI(out, individual.getModel(), individual.getURI());
            out.print(" [");
            for (Iterator j = individual.listLabels(null); j.hasNext();) {
                out.print(((Literal) j.next()).getString() + ", ");
            }
            out.print("] ");
            out.println();
        }
    }
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void nstring2047(PrintStream ps, String value) {
    if (value == null) {
        ps.write(NIL, 0, 3);/*from   w  w  w .  jav a  2s  . c  o m*/
        return;
    }

    boolean encoded = false;
    for (int i = 0, length = value.length(); i < length; i++) {
        char c = value.charAt(i);
        if (c == '"' || c == '\\' || c >= 0x7f || c < 0x20) {
            encoded = true;
        }
    }
    if (!encoded) {
        ps.write('"');
        ps.print(value);
        ps.write('"');
    } else {
        try {
            // can't use QCodec because it doesn't encode '"', which results in bad quoted-strings
            ps.write('"');
            ps.print(new BCodec().encode(value, "utf-8"));
            ps.write('"');
        } catch (EncoderException ee) {
            ps.write(NIL, 0, 3);
        }
    }
}