Example usage for java.io PrintWriter printf

List of usage examples for java.io PrintWriter printf

Introduction

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

Prototype

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

Source Link

Document

A convenience method to write 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 ava2  s. c  o m*/

        PrintWriter pw = new PrintWriter(System.out);

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

        // flush the writer
        pw.flush();

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

From source file:gobblin.compaction.CompactionRunner.java

public static void main(String[] args) throws ConfigurationException, IOException, SQLException {

    if (args.length != 1) {
        LOG.info("Proper usage: java -jar compaction.jar <global-config-file>\n" + "or\n"
                + "hadoop jar compaction.jar <global-config-file>\n" + "or\n"
                + "yarn jar compaction.jar <global-config-file>\n");
        System.exit(1);/*from   ww  w  .java  2  s . co m*/
    }

    Configuration globalConfig = new PropertiesConfiguration(args[0]);
    properties = ConfigurationConverter.getProperties(globalConfig);

    File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR));
    File[] listOfFiles = compactionConfigDir.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        System.err.println("No compaction configuration files found under " + compactionConfigDir);
        System.exit(1);
    }

    int numOfJobs = 0;
    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            numOfJobs++;
        }
    }
    LOG.info("Found " + numOfJobs + " compaction tasks.");
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(
            new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)),
            Charset.forName("UTF-8")));

    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath());
            jobProperties = ConfigurationConverter.getProperties(jobConfig);
            long startTime = System.nanoTime();
            compact();
            long endTime = System.nanoTime();
            long elapsedTime = endTime - startTime;
            double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime);
            pw.printf("%s: %f%n", file.getAbsolutePath(), seconds);
        }
    }

    pw.close();
}

From source file:Main.java

static void timeStamp(String msg, PrintWriter pw) {
    Calendar cal = Calendar.getInstance();
    pw.printf("%s %tc\n", msg, cal);
}

From source file:com.nridge.core.base.io.xml.IOXML.java

/**
 * Writes an XML tag attribute (name/value) while ensuring the characters
 * are properly escaped./*from  w  w  w.j  a  va2s .c o m*/
 *
 * @param aPW Print writer output stream.
 * @param aName Attribute name.
 * @param aValue Attribute value.
 *
 * @throws IOException I/O related exception.
 */
public static void writeAttrNameValue(PrintWriter aPW, String aName, int aValue) throws IOException {
    aPW.printf(" %s=\"%d\"", StringEscapeUtils.escapeXml10(aName), aValue);
}

From source file:com.nridge.core.base.io.xml.IOXML.java

/**
 * Writes an XML tag attribute (name/value) while ensuring the characters
 * are properly escaped.//from   w ww. j  av  a  2s  .  c  o m
 *
 * @param aPW Print writer output stream.
 * @param aName Attribute name.
 * @param aValue Attribute value.
 *
 * @throws IOException I/O related exception.
 */
public static void writeAttrNameValue(PrintWriter aPW, String aName, char aValue) throws IOException {
    aPW.printf(" %s=\"%c\"", StringEscapeUtils.escapeXml10(aName), aValue);
}

From source file:com.nridge.core.base.io.xml.IOXML.java

/**
 * Writes an XML tag attribute (name/value) while ensuring the characters
 * are properly escaped.//from  ww w.  java  2s. c o m
 *
 * @param aPW Print writer output stream.
 * @param aName Attribute name.
 * @param aValue Attribute value.
 *
 * @throws IOException I/O related exception.
 */
public static void writeAttrNameValue(PrintWriter aPW, String aName, long aValue) throws IOException {
    aPW.printf(" %s=\"%d\"", StringEscapeUtils.escapeXml10(aName), aValue);
}

From source file:com.nridge.core.base.io.xml.IOXML.java

/**
 * Writes an XML tag attribute (name/value) while ensuring the characters
 * are properly escaped.//from  ww  w .  j ava2  s  .c om
 *
 * @param aPW Print writer output stream.
 * @param aName Attribute name.
 * @param aValue Attribute value.
 *
 * @throws IOException I/O related exception.
 */
public static void writeAttrNameValue(PrintWriter aPW, String aName, boolean aValue) throws IOException {
    aPW.printf(" %s=\"%s\"", StringEscapeUtils.escapeXml10(aName), StrUtl.booleanToString(aValue));
}

From source file:com.tamingtext.tagging.LuceneTagExtractor.java

public static void emitTagDoc(Term term, PrintWriter pw, StringBuilder b) {

    if (b.length() < 100) {
        return;/*from w ww  . j  av  a2 s  .c om*/
    }

    pw.printf("%s\t%s\n", term.text(), b);
}

From source file:com.nridge.core.base.io.xml.IOXML.java

/**
 * Writes an XML tag attribute (name/value) while ensuring the characters
 * are properly escaped./*ww  w.  ja v  a2 s . c o m*/
 *
 * @param aPW Print writer output stream.
 * @param aName Attribute name.
 * @param aValue Attribute value.
 *
 * @throws IOException I/O related exception.
 */
public static void writeAttrNameValue(PrintWriter aPW, String aName, String aValue) throws IOException {
    if (StringUtils.isNotEmpty(aValue))
        aPW.printf(" %s=\"%s\"", StringEscapeUtils.escapeXml10(aName), StringEscapeUtils.escapeXml10(aValue));
}

From source file:com.tamingtext.tagging.LuceneTagExtractor.java

public static void emitTermsForTags(PrintWriter out, StringBuilder buf, IndexReader reader, TermFreqVector tv) {
    if (tv == null)
        return;/*from   w w w .j ava2  s .com*/

    String[] terms = tv.getTerms();

    for (int j = 0; j < terms.length; j++) {
        out.printf("%s\t%s\n", terms[j], buf.toString());
    }
}