Example usage for java.io PrintWriter format

List of usage examples for java.io PrintWriter format

Introduction

In this page you can find the example usage for java.io PrintWriter format.

Prototype

public PrintWriter format(Locale l, String format, Object... args) 

Source Link

Document

Writes a formatted string to this writer using the specified format string and arguments.

Usage

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {//from  www  .j  a va 2s  .  co m

        PrintWriter pw = new PrintWriter(System.out);

        // format text with specified locale.
        // %s indicates a string will be placed there, which is s
        pw.format(Locale.UK, "This is a %s program", s);

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:de.tudarmstadt.lt.seg.app.Segmenter.java

public static void split_and_tokenize(Reader reader, String docid, ISentenceSplitter sentenceSplitter,
        ITokenizer tokenizer, int level_filter, int level_normalize, boolean merge_types, boolean merge_tokens,
        String separator_sentence, String separator_token, String separator_desc, PrintWriter writer) {
    try {// w  w w  .ja v a  2s .  co m
        final StringBuffer buf = new StringBuffer(); // used for checking of stream is empty; take care when not running sequentially but in parallel!
        sentenceSplitter.init(reader).stream().sequential().forEach(sentence_segment -> {
            if (DEBUG) {
                writer.format("%s%s", docid, separator_desc);
                writer.println(sentence_segment.toString());
                writer.print(separator_sentence);
            }
            if (sentence_segment.type != SegmentType.SENTENCE)
                return;
            tokenizer.init(sentence_segment.asString());
            Stream<String> tokens = null;
            if (DEBUG)
                tokens = tokenizer.stream().map(x -> x.toString() + separator_token);
            else
                tokens = StreamSupport.stream(tokenizer
                        .filteredAndNormalizedTokens(level_filter, level_normalize, merge_types, merge_tokens)
                        .spliterator(), false).map(x -> x + separator_token);
            Spliterator<String> spliterator = tokens.spliterator();
            tokens = StreamSupport.stream(spliterator, false);
            buf.setLength(0);
            boolean empty = !spliterator.tryAdvance(x -> {
                buf.append(x);
            });
            if (empty)
                return;
            synchronized (writer) {
                // writer.write(Thread.currentThread().getId() + "\t");
                writer.format("%s%s", docid, separator_desc);
                writer.print(buf);
                tokens.forEach(writer::print);
                writer.print(separator_sentence);
                writer.flush();
            }
        });
    } catch (Exception e) {
        Throwable t = e;
        while (t != null) {
            System.err.format("%s: %s%n", e.getClass(), e.getMessage());
            t = e.getCause();
        }
    }
}

From source file:com.codefollower.lealone.omid.tso.Histogram.java

public void print(PrintWriter writer) {
    for (int i = 0; i <= max; ++i) {
        writer.format("%5d\t%5d\n", i, counts[i]);
    }/*w w w  .  j a  v a  2 s  .  c  o m*/
}

From source file:sf.net.experimaestro.server.XPMServlet.java

void header(PrintWriter out, String title) {
    out.format("<html><head><title>XPM@%s - %s</title>", escapeHtml(serverSettings.name), escapeHtml(title));

    out.format(/*from w w w  . j ava2  s  .c  o m*/
            "<link type=\"text/css\" href=\"/css/%s/jquery-ui-1.10.2.custom.min.css\" rel=\"stylesheet\"></link>%n",
            serverSettings.style.toString().toLowerCase());

    out.format(
            "<link type=\"text/css\" href=\"/js/jstree/themes/default/style.min.css\" rel=\"stylesheet\"></link>%n");

    out.format(
            "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/css/style.css\">\n");
    out.format("<script type=\"text/javascript\" src=\"/js/jquery-1.9.1.min.js\"></script>\n");
    out.format("<script type=\"text/javascript\" src=\"/js/jquery-ui-1.10.2.custom.min.js\"></script>\n");
    out.format("<script type=\"text/javascript\" src=\"/js/jquery.jsonrpc.js\"></script>\n");
    out.format("<script type=\"text/javascript\" src=\"/js/jstree/jstree.min.js\"></script>\n");

    out.format("<script type=\"text/javascript\" src=\"/js/jquery.ba-hashchange.min.js\"></script>\n");
    out.format("<script type=\"text/javascript\" src='/js/noty/jquery.noty.js'></script>%n");
    out.format("<script type=\"text/javascript\" src='/js/noty/layouts/top.js'></script>%n");
    out.format("<script type=\"text/javascript\" src='/js/noty/themes/default.js'></script>%n");

    out.format("<script type=\"text/javascript\" src=\"/js/xpm.js\"></script>\n");
    out.format("</head>%n");
    out.format("<body>%n");
    out.format("<div id=\"header\"><div class='title'>Experimaestro - %s</div>", serverSettings.name);
    out.format(
            "<div class='links'><a href=\"/status\">Status</a> <a href='/tasks'>Tasks</a> <a href='/jshelp'>JS Help</a></div></div>");

}

From source file:org.owasp.benchmark.testcode.BenchmarkTest00160.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    String param = request.getHeader("vector");
    if (param == null)
        param = "";

    String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param);

    Object[] obj = { "a", bar };
    java.io.PrintWriter out = response.getWriter();
    out.write("<!DOCTYPE html>\n<html>\n<body>\n<p>");
    out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj);
    out.write("\n</p>\n</body>\n</html>");
}

From source file:org.owasp.benchmark.testcode.BenchmarkTest00898.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    org.owasp.benchmark.helpers.SeparateClassRequest scr = new org.owasp.benchmark.helpers.SeparateClassRequest(
            request);/* w  ww . j  a  va 2  s.  c  om*/
    String param = scr.getTheValue("vector");

    String bar = org.apache.commons.lang.StringEscapeUtils.escapeHtml(param);

    Object[] obj = { "a", bar };
    java.io.PrintWriter out = response.getWriter();
    out.write("<!DOCTYPE html>\n<html>\n<body>\n<p>");
    out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj);
    out.write("\n</p>\n</body>\n</html>");
}

From source file:org.owasp.benchmark.testcode.BenchmarkTest02176.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    String param = request.getParameter("vector");
    if (param == null)
        param = "";

    String bar = doSomething(param);

    Object[] obj = { "a", bar };
    java.io.PrintWriter out = response.getWriter();
    out.write("<!DOCTYPE html>\n<html>\n<body>\n<p>");
    out.format(java.util.Locale.US, "Formatted like: %1$s and %2$s.", obj);
    out.write("\n</p>\n</body>\n</html>");
}

From source file:elkfed.mmax.visualize.Page.java

public void writeHTML(PrintWriter out) {
    writeHeader(out);/*  w ww .  j a v  a  2 s.  com*/
    out.println("function init_page() {");
    int num_extents = 0;
    int num_sent = 0;
    for (Sentence s : sentences) {
        out.format("addLayered(%s,%s);\n", JsonStringEncoder.getInstance().encodeAsUTF8(s.getName()),
                s.toJSONString());
        num_sent += 1;
        if (num_sent == 100) {
            out.format("addBarrier('init_page_%d()');\n}\n", ++num_extents);
            out.format("function init_page_%d() {\nremoveBarrier();\n", num_extents);
            num_sent = 0;
        }
    }
    out.println("}");
    out.println("// -->");
    out.println("</script>");
    out.println("</head><body onload=\"init_page()\">");
    out.println("</body></html>");
}

From source file:com.act.lcms.db.io.writer.PlateCompositionWriter.java

protected void writePlateAttributes(PrintWriter w, Plate plate) throws IOException {
    w.format(">%s\t%s\n", "name", plate.getName());
    w.format(">%s\t%s\n", "description", plate.getDescription());
    w.format(">%s\t%s\n", "barcode", plate.getBarcode());
    w.println(">schema\tplate\n");
    w.format(">%s\t%s\n", "location", plate.getLocation());
    w.format(">%s\t%s\n", "plate_type", plate.getPlateType());
    if (plate.getSolvent() != null) {
        w.format(">%s\t%s\n", "solvent", plate.getSolvent());
    }//from  ww w .j a  v  a2s . c o m
    w.format(">%s\t%d\n", "temperature", plate.getTemperature());
    w.println();
}

From source file:com.commercehub.dropwizard.BuildInfoServlet.java

private void writeAllHtml(HttpServletResponse response) throws IOException {
    response.setContentType(MediaType.TEXT_HTML);
    PrintWriter writer = response.getWriter();

    writer.println("<html>");
    writer.println("  <body>");
    writer.println("    <h1>Info</h1>");
    writer.println("    <ul>");
    for (String key : manifestAttributes.stringPropertyNames()) {
        writer.format("      <li>%s: %s</li>", key, manifestAttributes.get(key));
    }//  www  .j  a va  2 s  .c  o  m
    writer.println("    </ul>");
    writer.println("  </body>");
    writer.println("</html>");
}