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(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:de.tudarmstadt.ukp.experiments.argumentation.sequence.writers.HtmlWriter.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    try {// ww w.jav  a2s  .  c  o  m
        File outFile = new File(outputFolder, DocumentMetaData.get(aJCas).getDocumentId() + ".html");
        PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));

        // print header
        printHeader(aJCas, out);

        // print paragarphs
        List<String> paragraphs = renderDocumentToHtmlParagraphs(aJCas);
        out.printf("<p>%s</p>", StringUtils.join(paragraphs, "<br/><br/>"));

        out.printf("<hr />");

        // implicit claim?
        for (Claim claim : JCasUtil.select(aJCas, Claim.class)) {
            if (ArgumentUnitUtils.isImplicit(claim)) {
                out.printf(
                        "<p><span class=\"component\">Implicit claim:</span> <span class=\"claim\">%s</span></p>",
                        ArgumentUnitUtils.getProperty(claim, ArgumentUnitUtils.PROP_KEY_REPHRASED_CONTENT));
            }
        }

        // appeal to emotions
        for (ArgumentComponent component : JCasUtil.select(aJCas, ArgumentComponent.class)) {
            if (ArgumentUnitUtils.getProperty(component,
                    ArgumentUnitUtils.PROP_KEY_IS_APPEAL_TO_EMOTION) != null) {
                out.printf(
                        "<p><span class=\"component\">Appeal to emotions:</span> <span class=\"appeal\">%s</span></p>",
                        component.getCoveredText());
            }
        }

        // print footer
        printFooter(aJCas, out);

        IOUtils.closeQuietly(out);
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
}

From source file:io.github.gsteckman.rpi_rest.SubscriptionManager.java

/**
 * Generates the UPnP NOTIFY message string.
 * //from ww w.  j  a  v  a  2 s. c om
 * @param url
 *            URL for the subscriber.
 * @param contentType
 *            Content type header.
 * @param body
 *            message body content
 * @param uuid
 *            The universally unique subscription ID.
 * @param si
 *            Subscription info used to complete the message
 * @return The String for the message that should be transmitted to the subscriber.
 */
private String generateNotify(final URL url, String contentType, String body, UUID uuid, SubscriptionInfo si) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.printf("NOTIFY %s HTTP/1.1\r\n", url.getPath());
    pw.printf("HOST: %s:%d\r\n", url.getHost(), url.getPort());
    pw.printf("CONTENT-TYPE: %s\r\n", contentType);
    pw.printf("NT: upnp:event\r\n");
    pw.printf("NTS: upnp:propchange\r\n");
    pw.printf("SID: uuid:%s\r\n", uuid.toString());
    pw.printf("SEQ: %d\r\n", si.eventKey);
    pw.printf("CONTENT-LENGTH: %d\r\n", body.length());
    pw.printf("\r\n");
    pw.print(body);
    pw.flush();
    String resp = sw.toString();
    pw.close();
    return resp;
}

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

/**
 * Saves the previous assigned bag/table (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW PrintWriter stream instance.
 * @param aTagName Tag name.//w  w w . j  ava2  s  .co  m
 * @param anIndentAmount Indentation count.
 *
 * @throws IOException I/O related exception.
 */
public void save(PrintWriter aPW, String aTagName, int anIndentAmount) throws IOException {
    IOXML.indentLine(aPW, anIndentAmount);
    String tagName = StringUtils.remove(aTagName, StrUtl.CHAR_SPACE);
    aPW.printf("<%s", tagName);
    if (!mIsSimple) {
        IOXML.writeAttrNameValue(aPW, "type", IO.extractType(mBag.getClass().getName()));
        IOXML.writeAttrNameValue(aPW, "name", mBag.getName());
        IOXML.writeAttrNameValue(aPW, "title", mBag.getTitle());
        IOXML.writeAttrNameValue(aPW, "count", mBag.count());
        IOXML.writeAttrNameValue(aPW, "version", IO.DATABAG_XML_FORMAT_VERSION);
    }
    for (Map.Entry<String, String> featureEntry : mBag.getFeatures().entrySet())
        IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue());
    aPW.printf(">%n");

    for (DataField dataField : mBag.getFields()) {
        if (dataField.isAssigned()) {
            mDataFieldXML.saveNode(aPW, anIndentAmount + 1);
            mDataFieldXML.saveAttr(aPW, dataField);
            mDataFieldXML.saveValue(aPW, dataField, anIndentAmount + 1);
        }
    }

    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("</%s>%n", tagName);
}

From source file:org.apache.aurora.common.args.apt.Configuration.java

void store(Writer output, String message) {
    PrintWriter writer = new PrintWriter(output);
    writer.printf("# %s\n", new Date());
    writer.printf("# %s\n ", message);

    writer.println();/*w  w  w  .  j  a  v  a2s  .co  m*/
    for (ArgInfo info : cmdLineInfos) {
        writer.printf("field %s %s\n", info.className, info.fieldName);
    }

    writer.println();
    for (ParserInfo info : parserInfos) {
        writer.printf("parser %s %s\n", info.parsedType, info.parserClass);
    }

    writer.println();
    for (VerifierInfo info : verifierInfos) {
        writer.printf("verifier %s %s %s\n", info.verifiedType, info.verifyingAnnotation, info.verifierClass);
    }
}

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

/**
 * Saves the previous assigned bag list (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW PrintWriter stream instance.
 * @param aTagName Tag name./*  w  w  w .j a  v  a  2  s. c om*/
 * @param anIndentAmount Indentation count.
 *
 * @throws java.io.IOException I/O related exception.
 */
public void save(PrintWriter aPW, String aTagName, int anIndentAmount) throws IOException {
    DocumentXML documentXML;

    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("<%s", IO.XML_REPLY_NODE_NAME);
    IOXML.writeAttrNameValue(aPW, Doc.FEATURE_OP_STATUS_CODE, mField.getValue());
    int docCount = mDocumentList.size();
    if (docCount > 0)
        IOXML.writeAttrNameValue(aPW, "count", mDocumentList.size());
    for (Map.Entry<String, String> featureEntry : mField.getFeatures().entrySet())
        IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue());
    aPW.printf(">%n");

    for (Document document : mDocumentList) {
        documentXML = new DocumentXML(document);
        documentXML.setIsSimpleFlag(mIsSimple);
        documentXML.setSaveFieldsWithoutValues(true);
        documentXML.save(aPW, aTagName, anIndentAmount + 1);
    }

    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("</%s>%n", IO.XML_REPLY_NODE_NAME);
}

From source file:org.apache.sling.adapter.internal.AdapterWebConsolePlugin.java

public void printConfiguration(final PrintWriter pw) {
    pw.println("Current Apache Sling Adaptables:");
    for (final AdaptableDescription desc : allAdaptables) {
        pw.printf("Adaptable: %s\n", desc.adaptable);
        if (desc.condition != null) {
            pw.printf("Condition: %s\n", desc.condition);
        }/*from w  ww  .ja v a 2s.  co  m*/
        pw.printf("Providing Bundle: %s\n", desc.bundle.getSymbolicName());
        pw.printf("Available Adapters:\n");
        for (final String adapter : desc.adapters) {
            pw.print(" * ");
            pw.println(adapter);
        }
        pw.println();
    }
}

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

/**
 * Saves the previous assigned relationship (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW            PrintWriter stream instance.
 * @param aTagName       Tag name.//from   ww w. jav a2 s.  c  o  m
 * @param anIndentAmount Indentation count.
 *
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void save(PrintWriter aPW, String aTagName, int anIndentAmount) throws IOException {
    DocumentXML documentXML;

    IOXML.indentLine(aPW, anIndentAmount);
    String typeName = mRelationship.getType();
    String tagName = StringUtils.remove(aTagName, StrUtl.CHAR_SPACE);
    aPW.printf("<%s", tagName);
    IOXML.writeAttrNameValue(aPW, "type", typeName);
    for (Map.Entry<String, String> featureEntry : mRelationship.getFeatures().entrySet())
        IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue());
    aPW.printf(">%n");
    DataBag dataBag = mRelationship.getBag();
    if (dataBag.assignedCount() > 0) {
        DataBagXML dataBagXML = new DataBagXML(dataBag);
        dataBagXML.setBag(dataBag);
        dataBagXML.save(aPW, IO.XML_PROPERTIES_NODE_NAME, anIndentAmount + 1);
    }
    for (com.nridge.core.base.doc.Document document : mRelationship.getDocuments()) {
        documentXML = new DocumentXML(document);
        documentXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues);
        documentXML.save(aPW, IO.XML_DOCUMENT_NODE_NAME, document, anIndentAmount + 1);
    }
    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("</%s>%n", tagName);
}

From source file:com.twitter.common.args.apt.Configuration.java

void store(Writer output, String message) {
    PrintWriter writer = new PrintWriter(output);
    writer.printf("# %s\n", new Date());
    writer.printf("# %s\n ", message);

    writer.println();//  ww w .  j  a va 2  s .  c  o m
    for (ArgInfo info : positionalInfos) {
        writer.printf("positional %s %s\n", info.className, info.fieldName);
    }

    writer.println();
    for (ArgInfo info : cmdLineInfos) {
        writer.printf("field %s %s\n", info.className, info.fieldName);
    }

    writer.println();
    for (ParserInfo info : parserInfos) {
        writer.printf("parser %s %s\n", info.parsedType, info.parserClass);
    }

    writer.println();
    for (VerifierInfo info : verifierInfos) {
        writer.printf("verifier %s %s %s\n", info.verifiedType, info.verifyingAnnotation, info.verifierClass);
    }
}

From source file:com.mgmtp.perfload.core.console.meta.LtMetaInfoHandler.java

/**
 * Dumps the specified meta information to specified writer.
 * //w ww  . j a v  a  2 s. c  o m
 * @param metaInfo
 *            the meta information object
 * @param writer
 *            the writer
 */
public void dumpMetaInfo(final LtMetaInfo metaInfo, final Writer writer) {
    PrintWriter pr = new PrintWriter(writer);

    URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
    if (url.getPath().endsWith(".jar")) {
        try {
            JarFile jarFile = new JarFile(toFile(url));
            Manifest mf = jarFile.getManifest();
            Attributes attr = mf.getMainAttributes();
            pr.printf("perfload.implementation.version=%s", attr.getValue("Implementation-Version"));
            pr.println();
            pr.printf("perfload.implementation.date=%s", attr.getValue("Implementation-Date"));
            pr.println();
            pr.printf("perfload.implementation.revision=%s", attr.getValue("Implementation-Revision"));
            pr.println();
        } catch (IOException ex) {
            log.error(ex.getMessage(), ex);
        }
    }

    pr.printf("test.file=%s", metaInfo.getTestplanFileName());
    pr.println();

    pr.printf("test.start=%s", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(metaInfo.getStartTimestamp()));
    pr.println();
    pr.printf("test.finish=%s", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(metaInfo.getFinishTimestamp()));
    pr.println();

    List<Daemon> daemonList = metaInfo.getDaemons();
    Collections.sort(daemonList);

    for (Daemon daemon : daemonList) {
        pr.printf("daemon.%d=%s:%d", daemon.getId(), daemon.getHost(), daemon.getPort());
        pr.println();
    }

    List<String> lpTargets = metaInfo.getLpTargets();
    if (!lpTargets.isEmpty()) {
        Collections.sort(lpTargets);
        pr.printf("targets=%s", on(',').join(lpTargets));
        pr.println();
    }

    List<String> lpOperations = metaInfo.getLpOperations();
    if (!lpOperations.isEmpty()) {
        Collections.sort(lpOperations);
        pr.printf("operations=%s", on(',').join(lpOperations));
        pr.println();
    }

    List<Executions> executionsList = metaInfo.getExecutionsList();
    Collections.sort(executionsList);
    for (Executions executions : executionsList) {
        pr.printf("executions.%s.%s=%d", executions.operation, executions.target, executions.executions);
        pr.println();
    }
}

From source file:com.nridge.core.ds.io.xml.DataSourceXML.java

/**
 * Saves the previous assigned document (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW            PrintWriter stream instance.
 * @param aTagName       Tag name.//from   w w  w  .j  ava 2  s  .co  m
 * @param anIndentAmount Indentation count.
 *
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void save(PrintWriter aPW, String aTagName, int anIndentAmount) throws IOException {
    Logger appLogger = mAppMgr.getLogger(this, "save");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("<%s", aTagName);
    IOXML.writeAttrNameValue(aPW, "type", mDocument.getType());
    IOXML.writeAttrNameValue(aPW, "name", mDocument.getName());
    IOXML.writeAttrNameValue(aPW, "title", mDocument.getTitle());
    aPW.printf(">%n");

    DataBag dataBag = mDocument.getBag();
    DataField dataField = dataBag.getFieldByName("description");
    if ((dataField != null) && (StringUtils.isNotEmpty(dataField.getValue()))) {
        DataFieldXML dataFieldXML = new DataFieldXML();
        if (StringUtils.isNotEmpty(dataBag.getValueAsString("description"))) {
            dataFieldXML.saveNode(aPW, anIndentAmount + 1);
            dataFieldXML.saveAttr(aPW, dataField);
            dataFieldXML.saveValue(aPW, dataField, anIndentAmount + 1);
        }
    }

    String typeName = DS.RELATIONSHIP_CONFIGURATION;
    Relationship cfgRelationship = mDocument.getFirstRelationship(typeName);
    if (cfgRelationship != null) {
        DataBagXML dataBagXML = new DataBagXML(cfgRelationship.getBag());
        dataBagXML.setIsSimpleFlag(true);
        dataBagXML.save(aPW, typeName, anIndentAmount + 1);
    }

    typeName = DS.RELATIONSHIP_SCHEMA;
    Relationship schemaRelationship = mDocument.getFirstRelationship(typeName);
    if (schemaRelationship != null) {
        DataBagXML dataBagXML = new DataBagXML(schemaRelationship.getBag());
        dataBagXML.setIsSimpleFlag(true);
        dataBagXML.save(aPW, typeName, anIndentAmount + 1);
    }

    typeName = DS.RELATIONSHIP_VALUES;
    Relationship valuesRelationship = mDocument.getFirstRelationship(typeName);
    if (valuesRelationship != null) {
        DataBagXML dataBagXML = new DataBagXML(valuesRelationship.getBag());
        dataBagXML.setIsSimpleFlag(true);
        dataBagXML.save(aPW, typeName, anIndentAmount + 1);
    }

    Document criteriaDocument = mDocument.getFirstRelatedDocument(DS.RELATIONSHIP_CRITERIA);
    if (criteriaDocument != null) {
        DataBagXML dataBagXML = new DataBagXML(criteriaDocument.getBag());
        dataBagXML.setIsSimpleFlag(true);
        dataBagXML.save(aPW, DS.RELATIONSHIP_CRITERIA, anIndentAmount + 1);
    }

    IOXML.indentLine(aPW, anIndentAmount);
    aPW.printf("</%s>%n", aTagName);

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}