Example usage for java.io PrintStream printf

List of usage examples for java.io PrintStream printf

Introduction

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

Prototype

public PrintStream printf(String format, Object... args) 

Source Link

Document

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

Usage

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    PrintStream ps = new PrintStream(System.out);

    // printf this string
    ps.printf("This is a %s application", s);

    // flush the stream
    ps.flush();//w ww  .j  a va  2s  .  c om

}

From source file:org.cybergarage.round.ConsistentHash.java

public final static String GetHashCode(String seed) {
    try {/* w ww. java2s . c o m*/
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(seed.getBytes());
        byte[] digest = md.digest();

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(buffer);
        for (int i = 0; i < digest.length; i++) {
            ps.printf("%02x", (digest[i] & 0xff));
        }
        return buffer.toString();
    } catch (java.security.NoSuchAlgorithmException e) {
        return "";
    }
}

From source file:org.apache.hadoop.mapreduce.security.SecureShuffleUtils.java

/**
 * byte array to Hex String// w ww.  j a va 2s  .  c  om
 * @param ba
 * @return string with HEX value of the key
 */
public static String toHex(byte[] ba) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    for (byte b : ba) {
        ps.printf("%x", b);
    }
    return baos.toString();
}

From source file:mx.bigdata.cfdi.CFDv3.java

public static void dump(String title, byte[] bytes, PrintStream out) {
    out.printf("%s: ", title);
    for (byte b : bytes) {
        out.printf("%02x ", b & 0xff);
    }//w  w  w .  ja  v a2 s  . c o  m
    out.println();
}

From source file:com.lagrange.LabelApp.java

/**
 * Prints the labels received from the Vision API.
 *//*from w  ww . ja v a  2 s  .  c om*/
public static void printLabels(PrintStream out, Path imagePath, List<EntityAnnotation> labels) {
    out.printf("Labels for image %s:\n", imagePath);
    for (EntityAnnotation label : labels) {
        out.printf("\t%s (score: %.3f)\n", label.getDescription(), label.getScore());
    }
    try {
        sendPhotoToTelegramBot();
        sendMessageToTelegramBot(labels);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (labels.isEmpty()) {
        out.println("\tNo labels found.");
    }

}

From source file:mx.bigdata.sat.cfdi.CFDv3.java

static void dump(String title, byte[] bytes, PrintStream out) {
    out.printf("%s: ", title);
    for (byte b : bytes) {
        out.printf("%02x ", b & 0xff);
    }/*from w  w w.  ja  v a2 s  . c om*/
    out.println();
}

From source file:org.apache.hadoop.util.Crc32PerformanceTest.java

private static void printCell(String s, int width, PrintStream out) {
    final int w = s.length() > width ? s.length() : width;
    out.printf(" %" + w + "s |", s);
}

From source file:de.tudarmstadt.ukp.clarin.webanno.brat.curation.AgreementUtils.java

public static void dumpStudy(PrintStream aOut, ICodingAnnotationStudy aStudy) {
    try {//from   w w  w.j  a v a2 s.c o  m
        aOut.printf("Category count: %d%n", aStudy.getCategoryCount());
    } catch (Throwable e) {
        aOut.printf("Category count: %s%n", ExceptionUtils.getRootCauseMessage(e));
    }
    try {
        aOut.printf("Item count: %d%n", aStudy.getItemCount());
    } catch (Throwable e) {
        aOut.printf("Item count: %s%n", ExceptionUtils.getRootCauseMessage(e));
    }

    for (ICodingAnnotationItem item : aStudy.getItems()) {
        StringBuilder sb = new StringBuilder();
        for (IAnnotationUnit unit : item.getUnits()) {
            if (sb.length() > 0) {
                sb.append(" \t");
            }
            sb.append(unit.getCategory());
        }
        aOut.println(sb);
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.brat.curation.AgreementUtils.java

public static void dumpAgreementStudy(PrintStream aOut, AgreementResult aAgreement) {
    try {// w  w  w  .j a v  a  2 s.com
        aOut.printf("Category count: %d%n", aAgreement.getStudy().getCategoryCount());
    } catch (Throwable e) {
        aOut.printf("Category count: %s%n", ExceptionUtils.getRootCauseMessage(e));
    }
    try {
        aOut.printf("Item count: %d%n", aAgreement.getStudy().getItemCount());
    } catch (Throwable e) {
        aOut.printf("Item count: %s%n", ExceptionUtils.getRootCauseMessage(e));
    }

    List<ConfigurationSet> completeSets = aAgreement.getCompleteSets();
    int i = 0;
    for (ICodingAnnotationItem item : aAgreement.getStudy().getItems()) {
        StringBuilder sb = new StringBuilder();
        sb.append(completeSets.get(i).getPosition());
        for (IAnnotationUnit unit : item.getUnits()) {
            if (sb.length() > 0) {
                sb.append(" \t");
            }
            sb.append(unit.getCategory());
        }
        aOut.println(sb);
        i++;
    }
}

From source file:com.sangupta.clitools.file.HexDump.java

public static void hexDump(PrintStream outStream, BufferedInputStream bis, int currentRow, int maxRows)
        throws IOException {
    int row = currentRow + 1;
    if (maxRows == 0) {
        maxRows = Integer.MAX_VALUE;
    } else {// w w  w  . j a  v  a 2  s .  com
        maxRows += currentRow;
    }

    StringBuilder builder1 = new StringBuilder(100);
    StringBuilder builder2 = new StringBuilder(100);

    while (bis.available() > 0) {
        outStream.printf("%04X  ", row * 16);
        for (int j = 0; j < 16; j++) {
            if (bis.available() > 0) {
                int value = (int) bis.read();
                builder1.append(String.format("%02X ", value));

                if (!Character.isISOControl(value)) {
                    builder2.append((char) value);
                } else {
                    builder2.append(".");
                }
            } else {
                for (; j < 16; j++) {
                    builder1.append("   ");
                }
            }
        }
        outStream.print(builder1);
        outStream.println(builder2);
        row++;

        if (row > maxRows) {
            break;
        }

        builder1.setLength(0);
        builder2.setLength(0);
    }
}