Example usage for java.util Formatter format

List of usage examples for java.util Formatter format

Introduction

In this page you can find the example usage for java.util Formatter format.

Prototype

public Formatter format(String format, Object... args) 

Source Link

Document

Writes a formatted string to this object's destination using the specified format string and arguments.

Usage

From source file:fr.inrialpes.exmo.align.cli.WGroupEval.java

public void printHTML(Vector<Vector<Object>> result, PrintStream writer) {
    // variables for computing iterative harmonic means
    int expected = 0; // expected so far
    int foundVect[]; // found so far
    int correctFoundVect[]; // correct so far
    int correctExpVect[]; // correct so far
    long timeVect[]; // time so far
    fsize = format.length();/*from w w w  . j a  v  a 2 s .c  om*/
    // JE: the writer should be put out
    // JE: the h-means computation should be put out as well
    Formatter formatter = new Formatter(writer);

    // Print the header
    if (embedded != true)
        writer.println("<html><head></head><body>");
    writer.println("<table border='2' frame='sides' rules='groups'>");
    writer.println("<colgroup align='center' />");
    // for each algo <td spancol='2'>name</td>
    for (String m : listAlgo) {
        writer.println("<colgroup align='center' span='" + fsize + "' />");
    }
    // For each file do a
    writer.println("<thead valign='top'><tr><th>algo</th>");
    // for each algo <td spancol='2'>name</td>
    for (String m : listAlgo) {
        writer.println("<th colspan='" + fsize + "'>" + m + "</th>");
    }
    writer.println("</tr></thead><tbody><tr><td>test</td>");
    // for each algo <td>Prec.</td><td>Rec.</td>
    for (String m : listAlgo) {
        for (int i = 0; i < fsize; i++) {
            writer.print("<td>");
            if (format.charAt(i) == 'p') {
                writer.print("Prec.");
            } else if (format.charAt(i) == 'f') {
                writer.print("FMeas.");
            } else if (format.charAt(i) == 'o') {
                writer.print("Over.");
            } else if (format.charAt(i) == 't') {
                writer.print("Time");
            } else if (format.charAt(i) == 'r') {
                writer.print("Rec.");
            }
            writer.println("</td>");
        }
        //writer.println("<td>Prec.</td><td>Rec.</td>");
    }
    writer.println("</tr></tbody><tbody>");
    foundVect = new int[size];
    correctFoundVect = new int[size];
    correctExpVect = new int[size];
    timeVect = new long[size];
    for (int k = size - 1; k >= 0; k--) {
        foundVect[k] = 0;
        correctFoundVect[k] = 0;
        correctExpVect[k] = 0;
        timeVect[k] = 0;
    }
    // </tr>
    // For each directory <tr>
    boolean colored = false;
    for (Vector<Object> test : result) {
        double newexpected = -1.;
        if (colored == true && color != null) {
            colored = false;
            writer.println("<tr bgcolor=\"" + color + "\">");
        } else {
            colored = true;
            writer.println("<tr>");
        }
        ;
        // Print the directory <td>bla</td>
        writer.println("<td>" + (String) test.get(0) + "</td>");
        // For each record print the values <td>bla</td>
        Enumeration<Object> f = test.elements();
        f.nextElement();
        for (int k = 0; f.hasMoreElements(); k++) {
            WeightedPREvaluator eval = (WeightedPREvaluator) f.nextElement();
            if (eval != null) {
                // iterative H-means computation
                if (newexpected == -1.) {
                    newexpected = eval.getExpected();
                    expected += newexpected;
                }
                foundVect[k] += eval.getFound();
                correctFoundVect[k] += eval.getCorrectFound();
                correctExpVect[k] += eval.getCorrectExpected();
                timeVect[k] += eval.getTime();

                for (int i = 0; i < fsize; i++) {
                    writer.print("<td>");
                    if (format.charAt(i) == 'p') {
                        formatter.format("%1.2f", eval.getPrecision());
                    } else if (format.charAt(i) == 'f') {
                        formatter.format("%1.2f", eval.getFmeasure());
                    } else if (format.charAt(i) == 'o') {
                        formatter.format("%1.2f", eval.getOverall());
                    } else if (format.charAt(i) == 't') {
                        if (eval.getTime() == 0) {
                            writer.print("-");
                        } else {
                            formatter.format("%1.2f", eval.getTime());
                        }
                    } else if (format.charAt(i) == 'r') {
                        formatter.format("%1.2f", eval.getRecall());
                    }
                    writer.println("</td>");
                }
            } else { // JE 2013: will break if the previous tests are all NULL
                correctExpVect[k] += newexpected;
                // Nothing needs to be incremented for precision
                for (int i = 0; i < fsize; i++)
                    writer.print("<td>n/a</td>");
                writer.println();
            }
        }
        writer.println("</tr>");
    }
    writer.print("<tr bgcolor=\"yellow\"><td>H-mean</td>");
    // Here we are computing a sheer average.
    // While in the column results we print NaN when the returned
    // alignment is empty,
    // here we use the real values, i.e., add 0 to both correctVect and
    // foundVect, so this is OK for computing the average.
    int k = 0;
    // ???
    for (String m : listAlgo) {
        double precision = 1. - (double) correctFoundVect[k] / foundVect[k];
        double recall = 1. - (double) correctExpVect[k] / expected;
        for (int i = 0; i < fsize; i++) {
            writer.print("<td>");
            if (format.charAt(i) == 'p') {
                formatter.format("%1.2f", precision);
            } else if (format.charAt(i) == 'f') {
                formatter.format("%1.2f", 2 * precision * recall / (precision + recall));
            } else if (format.charAt(i) == 'o') {
                formatter.format("%1.2f", recall * (2 - (1 / precision)));
            } else if (format.charAt(i) == 't') {
                if (timeVect[k] == 0) {
                    writer.print("-");
                } else {
                    formatter.format("%1.2f", timeVect[k]);
                }
            } else if (format.charAt(i) == 'r') {
                formatter.format("%1.2f", recall);
            }
            writer.println("</td>");
        }
        ;
        k++;
    }
    writer.println("</tr>");
    writer.println("</tbody></table>");
    writer.println("<p><small>n/a: result alignment not provided or not readable<br />");
    writer.println("NaN: division per zero, likely due to empty alignment.</small></p>");
    if (embedded != true)
        writer.println("</body></html>");
}

From source file:fr.inrialpes.exmo.align.cli.ExtGroupEval.java

public void printHTML(Vector<Vector<Object>> result, PrintStream writer) {
    // variables for computing iterative harmonic means
    int expected = 0; // expected so far
    int foundVect[]; // found so far
    double symVect[]; // symmetric similarity
    double effVect[]; // effort-based similarity
    double precOrVect[]; // precision-oriented similarity
    double recOrVect[]; // recall-oriented similarity

    fsize = format.length();/*from   ww  w  . jav  a2 s .  co  m*/
    try {
        Formatter formatter = new Formatter(writer);
        // Print the header
        writer.println("<html><head></head><body>");
        writer.println("<table border='2' frame='sides' rules='groups'>");
        writer.println("<colgroup align='center' />");
        // for each algo <td spancol='2'>name</td>
        for (String m : listAlgo) {
            writer.println("<colgroup align='center' span='" + 2 * fsize + "' />");
        }
        // For each file do a
        writer.println("<thead valign='top'><tr><th>algo</th>");
        // for each algo <td spancol='2'>name</td>
        for (String m : listAlgo) {
            writer.println("<th colspan='" + ((2 * fsize)) + "'>" + m + "</th>");
        }
        writer.println("</tr></thead><tbody><tr><td>test</td>");
        // for each algo <td>Prec.</td><td>Rec.</td>
        for (String m : listAlgo) {
            for (int i = 0; i < fsize; i++) {
                if (format.charAt(i) == 's') {
                    writer.println("<td colspan='2'><center>Symmetric</center></td>");
                } else if (format.charAt(i) == 'e') {
                    writer.println("<td colspan='2'><center>Effort</center></td>");
                } else if (format.charAt(i) == 'p') {
                    writer.println("<td colspan='2'><center>Prec. orient.</center></td>");
                } else if (format.charAt(i) == 'r') {
                    writer.println("<td colspan='2'><center>Rec. orient.</center></td>");
                }
            }
            //writer.println("<td>Prec.</td><td>Rec.</td>");
        }
        writer.println("</tr></tbody><tbody>");
        foundVect = new int[size];
        symVect = new double[size];
        effVect = new double[size];
        precOrVect = new double[size];
        recOrVect = new double[size];
        for (int k = size - 1; k >= 0; k--) {
            foundVect[k] = 0;
            symVect[k] = 0.;
            effVect[k] = 0.;
            precOrVect[k] = 0.;
            recOrVect[k] = 0.;
        }
        // </tr>
        // For each directory <tr>
        boolean colored = false;
        for (Vector<Object> test : result) {
            int nexpected = -1;
            if (colored == true && color != null) {
                colored = false;
                writer.println("<tr bgcolor=\"" + color + "\">");
            } else {
                colored = true;
                writer.println("<tr>");
            }
            ;
            // Print the directory <td>bla</td>
            writer.println("<td>" + (String) test.get(0) + "</td>");
            // For each record print the values <td>bla</td>
            Enumeration<Object> f = test.elements();
            f.nextElement();
            for (int k = 0; f.hasMoreElements(); k++) {
                ExtPREvaluator eval = (ExtPREvaluator) f.nextElement();
                if (eval != null) {
                    // iterative H-means computation
                    if (nexpected == -1) {
                        nexpected = eval.getExpected();
                        expected += nexpected;
                    }
                    // If foundVect is -1 then results are invalid
                    if (foundVect[k] != -1)
                        foundVect[k] += eval.getFound();
                    for (int i = 0; i < fsize; i++) {
                        writer.print("<td>");
                        if (format.charAt(i) == 's') {
                            formatter.format("%1.2f", eval.getSymPrecision());
                            writer.print("</td><td>");
                            formatter.format("%1.2f", eval.getSymRecall());
                            symVect[k] += eval.getSymSimilarity();
                        } else if (format.charAt(i) == 'e') {
                            formatter.format("%1.2f", eval.getEffPrecision());
                            writer.print("</td><td>");
                            formatter.format("%1.2f", eval.getEffRecall());
                            effVect[k] += eval.getEffSimilarity();
                        } else if (format.charAt(i) == 'p') {
                            formatter.format("%1.2f", eval.getPrecisionOrientedPrecision());
                            writer.print("</td><td>");
                            formatter.format("%1.2f", eval.getPrecisionOrientedRecall());
                            precOrVect[k] += eval.getPrecisionOrientedSimilarity();
                        } else if (format.charAt(i) == 'r') {
                            formatter.format("%1.2f", eval.getRecallOrientedPrecision());
                            writer.print("</td><td>");
                            formatter.format("%1.2f", eval.getRecallOrientedRecall());
                            recOrVect[k] += eval.getRecallOrientedSimilarity();
                        }
                        writer.print("</td>");
                    }
                } else {
                    for (int i = 0; i < fsize; i++)
                        writer.print("<td>n/a</td>");
                }
            }
            writer.println("</tr>");
        }
        writer.print("<tr bgcolor=\"yellow\"><td>H-mean</td>");
        int k = 0;
        for (String m : listAlgo) {
            if (foundVect[k] != -1) {
                for (int i = 0; i < fsize; i++) {
                    writer.print("<td>");
                    if (format.charAt(i) == 's') {
                        formatter.format("%1.2f", symVect[k] / foundVect[k]);
                        writer.print("</td><td>");
                        formatter.format("%1.2f", symVect[k] / expected);
                    } else if (format.charAt(i) == 'e') {
                        formatter.format("%1.2f", effVect[k] / foundVect[k]);
                        writer.print("</td><td>");
                        formatter.format("%1.2f", effVect[k] / expected);
                    } else if (format.charAt(i) == 'p') {
                        formatter.format("%1.2f", precOrVect[k] / foundVect[k]);
                        writer.print("</td><td>");
                        formatter.format("%1.2f", precOrVect[k] / expected);
                    } else if (format.charAt(i) == 'r') {
                        formatter.format("%1.2f", recOrVect[k] / foundVect[k]);
                        writer.print("</td><td>");
                        formatter.format("%1.2f", recOrVect[k] / expected);
                    }
                    writer.println("</td>");
                }
            } else {
                writer.println("<td colspan='2'><center>Error</center></td>");
            }
            //};
            k++;
        }
        writer.println("</tr>");
        writer.println("</tbody></table>");
        writer.println("<p><small>n/a: result alignment not provided or not readable<br />");
        writer.println("NaN: division per zero, likely due to empty alignent.</small></p>");
        writer.println("</body></html>");
    } catch (Exception ex) {
        logger.debug("IGNORED Exception", ex);
    } finally {
        writer.flush();
        writer.close();
    }
}

From source file:com.admc.jcreole.Indexer.java

/**
 * This is a highly-modified fork of Tomcat's method
 * DefaultServlet.renderHtml().// www.  j  ava  2 s . c om
 *
 * @param directory  Will throw an IllegalArgumentException if this is not
 *        a real directory.
 * @param listUp  Generate an entry for "..".
 * @return HTML fragment that is a HTML table element.
 */
public StringBuilder generateTable(File directory, String displayName, boolean listUp,
        FileComparator.SortBy sortBy, boolean ascendSort) {
    /*
     * TODO: Use an EnumMap or something to cache FileComparators instead
     * of instantiating one for every method call.
     */
    Matcher matcher = null;
    if (!directory.isDirectory())
        throw new IllegalArgumentException("Not a directory:  " + directory.getAbsolutePath());
    if ((namePattern == null && nameFormatString != null) || (namePattern != null && nameFormatString == null))
        throw new IllegalStateException(
                "'namePattern' and 'nameFormatString' must either both be " + "set or both be null");
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb);

    String name = displayName;

    sb.append("<table class=\"jcreole_dirindex\" width=\"100%\" "
            + "cellspacing=\"0\" cellpadding=\"5\" align=\"center\">\r\n");

    // Render the column headings
    sb.append("<tr>\r\n");
    sb.append("<td align=\"left\"><font size=\"+1\"><strong>");
    sb.append("<a href=\"?sort=");
    try {
        sb.append(URLEncoder.encode((sortBy == FileComparator.SortBy.NAME && ascendSort) ? "-" : "+", "UTF-8"));
        sb.append("NAME\">Nodename</a>");
        if (sortBy == FileComparator.SortBy.NAME)
            sb.append("<sup>").append(ascendSort ? '+' : '-').append("</sup>");
        sb.append("</strong></font></td>\r\n");
        sb.append("<td align=\"center\"><font size=\"+1\"><strong>");
        sb.append("<a href=\"?sort=");
        sb.append(URLEncoder.encode((sortBy == FileComparator.SortBy.SIZE && ascendSort) ? "-" : "+", "UTF-8"));
        sb.append("SIZE\">Size</a>");
        if (sortBy == FileComparator.SortBy.SIZE)
            sb.append("<sup>").append(ascendSort ? '+' : '-').append("</sup>");
        sb.append("</strong></font></td>\r\n");
        sb.append("<td align=\"right\"><font size=\"+1\"><strong>");
        sb.append("<a href=\"?sort=");
        sb.append(URLEncoder.encode((sortBy == FileComparator.SortBy.MODIFIED && ascendSort) ? "-" : "+",
                "UTF-8"));
    } catch (UnsupportedEncodingException uee) {
        throw new RuntimeException("Unable to encode to UTF-8");
    }
    sb.append("MODIFIED\">Last Modified</a>");
    if (sortBy == FileComparator.SortBy.MODIFIED)
        sb.append("<sup>").append(ascendSort ? '+' : '-').append("</sup>");
    sb.append("</strong></font></td>\r\n");
    sb.append("</tr>");

    boolean shade = true;

    // DIR ENTRY:
    if (listUp) {
        sb.append("<tr");
        sb.append(" bgcolor=\"#eeeeee\"");
        sb.append(">\r\n");

        sb.append("<td align=\"left\">&nbsp;&nbsp;\r\n");
        sb.append("<a href=\"../\"><tt><strong>..</strong>&nbsp;&nbsp;(");
        sb.append(StringEscapeUtils.escapeHtml(tailStripperPattern.matcher(displayName).replaceFirst("")));
        sb.append(")</tt></a></td>\r\n");

        sb.append("<td align=\"right\"><tt>");
        sb.append("&nbsp;");
        sb.append("</tt></td>\r\n");

        sb.append("<td align=\"right\"><tt>");
        sb.append(StringEscapeUtils
                .escapeHtml(isoDateTimeFormatter.format(directory.getParentFile().lastModified())));
        sb.append("</tt></td>\r\n");

        sb.append("</tr>\r\n");
    } // END DIR ENTRY

    List<File> fileList = Arrays.asList(directory.listFiles(filter));
    Collections.sort(fileList, new FileComparator(sortBy, ascendSort));

    // Render the directory entries within this directory
    for (File file : fileList) {
        String nodeName = file.getName();
        if (namePattern != null) {
            if (file.isFile()) {
                matcher = namePattern.matcher(nodeName);
                if (!matcher.matches())
                    continue;
            } else {
                matcher = null;
            }
        }

        shade = !shade;
        sb.append("<tr");
        if (shade)
            sb.append(" bgcolor=\"#eeeeee\"");
        sb.append(">\r\n");

        sb.append("<td align=\"left\">&nbsp;&nbsp;\r\n");
        sb.append("<a href=\"");
        if (matcher == null) {
            sb.append(nodeName);
        } else {
            // Terrible hack dur to terrible Java varargs limitation:
            switch (matcher.groupCount()) {
            case 1:
                formatter.format(nameFormatString, matcher.group(1));
                break;
            case 2:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2));
                break;
            case 3:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3));
                break;
            case 4:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3),
                        matcher.group(4));
                break;
            case 5:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3),
                        matcher.group(4), matcher.group(5));
                break;
            case 6:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3),
                        matcher.group(4), matcher.group(5), matcher.group(6));
                break;
            case 7:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3),
                        matcher.group(4), matcher.group(5), matcher.group(6), matcher.group(7));
                break;
            case 8:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3),
                        matcher.group(4), matcher.group(5), matcher.group(6), matcher.group(7),
                        matcher.group(8));
                break;
            case 9:
                formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3),
                        matcher.group(4), matcher.group(5), matcher.group(6), matcher.group(7),
                        matcher.group(8), matcher.group(9));
                break;
            default:
                throw new IllegalArgumentException(
                        "Pattern captured too many (" + matcher.groupCount() + ") groups: " + namePattern);
            }
        }
        if (file.isDirectory())
            sb.append('/');
        sb.append("\"><tt>");
        sb.append(StringEscapeUtils.escapeHtml(nodeName));
        if (file.isDirectory())
            sb.append('/');
        sb.append("</tt></a></td>\r\n");

        sb.append("<td align=\"right\"><tt>");
        if (file.isDirectory())
            sb.append("&nbsp;");
        else if (file.isFile())
            sb.append(file.length());
        sb.append("</tt></td>\r\n");

        sb.append("<td align=\"right\"><tt>");
        sb.append(StringEscapeUtils.escapeHtml(isoDateTimeFormatter.format(file.lastModified())));
        sb.append("</tt></td>\r\n");

        sb.append("</tr>\r\n");
    }

    // Render the page footer
    sb.append("</table>\r\n");

    return sb;
}

From source file:fr.inrialpes.exmo.align.cli.GroupEval.java

public void printHTML(Vector<Vector<Object>> result, PrintStream writer) {
    // variables for computing iterative harmonic means
    int expected = 0; // expected so far
    int foundVect[]; // found so far
    int correctVect[]; // correct so far
    long timeVect[]; // time so far
    Formatter formatter = new Formatter(writer);

    fsize = format.length();/* www .  j  av a  2s.  c o  m*/
    // JE: the h-means computation should be put out as well
    // Print the header
    if (embedded != true)
        writer.println("<html><head></head><body>");
    writer.println("<table border='2' frame='sides' rules='groups'>");
    writer.println("<colgroup align='center' />");
    // for each algo <td spancol='2'>name</td>
    for (String m : listAlgo) {
        writer.println("<colgroup align='center' span='" + fsize + "' />");
    }
    // For each file do a
    writer.println("<thead valign='top'><tr><th>algo</th>");
    // for each algo <td spancol='2'>name</td>
    for (String m : listAlgo) {
        writer.println("<th colspan='" + fsize + "'>" + m + "</th>");
    }
    writer.println("</tr></thead><tbody><tr><td>test</td>");
    // for each algo <td>Prec.</td><td>Rec.</td>
    for (String m : listAlgo) {
        for (int i = 0; i < fsize; i++) {
            writer.print("<td>");
            if (format.charAt(i) == 'p') {
                writer.print("Prec.");
            } else if (format.charAt(i) == 'f') {
                writer.print("FMeas.");
            } else if (format.charAt(i) == 'o') {
                writer.print("Over.");
            } else if (format.charAt(i) == 't') {
                writer.print("Time");
            } else if (format.charAt(i) == 'r') {
                writer.print("Rec.");
            }
            writer.println("</td>");
        }
        //writer.println("<td>Prec.</td><td>Rec.</td>");
    }
    writer.println("</tr></tbody><tbody>");
    foundVect = new int[size];
    correctVect = new int[size];
    timeVect = new long[size];
    for (int k = size - 1; k >= 0; k--) {
        foundVect[k] = 0;
        correctVect[k] = 0;
        timeVect[k] = 0;
    }
    // </tr>
    // For each directory <tr>
    boolean colored = false;
    for (Vector<Object> test : result) {
        int nexpected = -1;
        if (colored == true && color != null) {
            colored = false;
            writer.println("<tr bgcolor=\"" + color + "\">");
        } else {
            colored = true;
            writer.println("<tr>");
        }
        ;
        // Print the directory <td>bla</td>
        writer.println("<td>" + (String) test.get(0) + "</td>");
        // For each record print the values <td>bla</td>
        Enumeration<Object> f = test.elements();
        f.nextElement();
        for (int k = 0; f.hasMoreElements(); k++) {
            PRecEvaluator eval = (PRecEvaluator) f.nextElement();
            if (eval != null) {
                // iterative H-means computation
                if (nexpected == -1) {
                    expected += eval.getExpected();
                    nexpected = 0;
                }
                foundVect[k] += eval.getFound();
                correctVect[k] += eval.getCorrect();
                timeVect[k] += eval.getTime();

                for (int i = 0; i < fsize; i++) {
                    writer.print("<td>");
                    if (format.charAt(i) == 'p') {
                        formatter.format("%1.2f", eval.getPrecision());
                    } else if (format.charAt(i) == 'f') {
                        formatter.format("%1.2f", eval.getFmeasure());
                    } else if (format.charAt(i) == 'o') {
                        formatter.format("%1.2f", eval.getOverall());
                    } else if (format.charAt(i) == 't') {
                        if (eval.getTime() == 0) {
                            writer.print("-");
                        } else {
                            formatter.format("%1.2f", eval.getTime());
                        }
                    } else if (format.charAt(i) == 'r') {
                        formatter.format("%1.2f", eval.getRecall());
                    }
                    writer.print("</td>");
                }
            } else {
                for (int i = 0; i < fsize; i++)
                    writer.print("<td>n/a</td>");
            }
        }
        writer.println("</tr>");
    }
    writer.print("<tr bgcolor=\"yellow\"><td>H-mean</td>");
    // Here we are computing a sheer average.
    // While in the column results we print NaN when the returned
    // alignment is empty,
    // here we use the real values, i.e., add 0 to both correctVect and
    // foundVect, so this is OK for computing the average.
    int k = 0;
    // ???
    for (String m : listAlgo) {
        double precision = (double) correctVect[k] / foundVect[k];
        double recall = (double) correctVect[k] / expected;
        for (int i = 0; i < fsize; i++) {
            writer.print("<td>");
            if (format.charAt(i) == 'p') {
                formatter.format("%1.2f", precision);
            } else if (format.charAt(i) == 'f') {
                formatter.format("%1.2f", 2 * precision * recall / (precision + recall));
            } else if (format.charAt(i) == 'o') {
                formatter.format("%1.2f", recall * (2 - (1 / precision)));
            } else if (format.charAt(i) == 't') {
                if (timeVect[k] == 0) {
                    writer.print("-");
                } else {
                    formatter.format("%1.2f", timeVect[k]);
                }
            } else if (format.charAt(i) == 'r') {
                formatter.format("%1.2f", recall);
            }
            writer.println("</td>");
        }
        ;
        k++;
    }
    writer.println("</tr>");
    writer.println("</tbody></table>");
    writer.println("<p><small>n/a: result alignment not provided or not readable<br />");
    writer.println("NaN: division per zero, likely due to empty alignment.</small></p>");
    if (embedded != true)
        writer.println("</body></html>");
}

From source file:org.openme.openme.java

private static String byteToHexString(byte[] bytes) {
    Formatter formatter = new Formatter();

    for (byte b : bytes)
        formatter.format("%02x", b);

    return formatter.toString();
}