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:com.aliyun.openservices.odps.console.commands.DescribeProjectCommand.java

@Override
public void run() throws OdpsException, ODPSConsoleException {
    Odps odps = getCurrentOdps();//from   w ww . jav  a 2 s  .  c  o  m

    Project prj = odps.projects().get(projectName);
    prj.reload();

    ExecutionContext context = getContext();
    PrintWriter out = new PrintWriter(System.out);
    out.printf("%-40s%-40s\n", "Name", prj.getName());
    out.printf("%-40s%-40s\n", "Description", prj.getComment());
    out.printf("%-40s%-40s\n", "Owner", prj.getOwner());
    out.printf("%-40s%-40s\n", "CreatedTime", prj.getCreatedTime());

    Map<String, String> properties = prj.getProperties();
    if (properties != null) {
        out.println("\nProperties:");
        for (Map.Entry<String, String> e : properties.entrySet()) {
            out.printf("%-40s%-40s\n", e.getKey(), e.getValue());
        }
    }

    if (extended) {
        Map<String, String> extendedProperties = prj.getExtendedProperties();
        out.println("\nExtended Properties:");
        if (extendedProperties != null) {
            for (Map.Entry<String, String> e : extendedProperties.entrySet()) {
                out.printf("%-40s%-40s\n", e.getKey(), e.getValue());
            }
        }
    }

    out.flush();
    //Security Configuration use Show Security Configuration
    //Not Display in Desc Project
}

From source file:org.bdval.ExecuteSplitsMode.java

@SuppressWarnings("unchecked")
private static void writeConditions(final String conditionsFilename, final JSAP jsap,
        final JSAPResult jsapResult, final Map<String, String> additionalConditionsMap,
        final Set<String> skipJsapConditions) throws IOException {
    PrintWriter modelConditionsWriter = null;
    try {/*  w ww. ja v a  2  s .c om*/
        modelConditionsWriter = new PrintWriter(new FileWriter(conditionsFilename, true));
        boolean firstItem = true;

        // Write the additional conditions
        for (final String conditionKey : additionalConditionsMap.keySet()) {
            final String value = additionalConditionsMap.get(conditionKey);
            if (firstItem) {
                firstItem = false;
            } else {
                modelConditionsWriter.print("\t");
            }
            modelConditionsWriter.printf("%s=%s", conditionKey, value);
        }

        // Write the JSAP configuration, as configured for ExecuteSplitsMode
        for (final String id : new IteratorIterable<String>(jsap.getIDMap().idIterator())) {
            if (skipJsapConditions.contains(id)) {
                // Skip some of the conditions
                continue;
            }
            final Parameter paramObj = jsap.getByID(id);
            if (paramObj instanceof Switch) {
                if (jsapResult.getBoolean(id)) {
                    if (firstItem) {
                        firstItem = false;
                    } else {
                        modelConditionsWriter.print("\t");
                    }
                    modelConditionsWriter.printf("%s=enabled", id);
                }
            } else if (paramObj instanceof FlaggedOption) {
                // A flag switch exists. Pass it along.
                final FlaggedOption flagOpt = (FlaggedOption) paramObj;
                if (jsapResult.contains(id)) {
                    if (firstItem) {
                        firstItem = false;
                    } else {
                        modelConditionsWriter.print("\t");
                    }
                    final String stringVal = SequenceMode.jsapOptionToConcatenatedString(jsapResult, flagOpt,
                            ',');
                    modelConditionsWriter.printf("%s=%s", id, stringVal);
                }
            }
        }
        modelConditionsWriter.println();
    } finally {
        IOUtils.closeQuietly(modelConditionsWriter);
        modelConditionsWriter = null;
    }
}

From source file:com.aliyun.openservices.odps.console.commands.DescribeInstanceCommand.java

@Override
public void run() throws OdpsException, ODPSConsoleException {
    Odps odps = getCurrentOdps();/*  w  ww .j av a  2s  .com*/
    if (!(odps.instances().exists(projectName, instanceId))) {
        throw new ODPSConsoleException("Instance not found : " + instanceId);
    }
    Instance i = odps.instances().get(projectName, instanceId);

    PrintWriter out = new PrintWriter(System.out);

    out.printf("%-40s%-40s\n", "ID", i.getId());
    out.printf("%-40s%-40s\n", "Owner", i.getOwner());
    out.printf("%-40s%-40s\n", "StartTime", DATE_FORMAT.format(i.getStartTime()));
    if (i.getEndTime() != null) {
        out.printf("%-40s%-40s\n", "EndTime", DATE_FORMAT.format(i.getEndTime()));
    }
    out.printf("%-40s%-40s\n", "Status", i.getStatus());
    for (Map.Entry<String, Instance.TaskStatus> entry : i.getTaskStatus().entrySet()) {
        out.printf("%-40s%-40s\n", entry.getKey(),
                StringUtils.capitalize(entry.getValue().getStatus().toString().toLowerCase()));
    }
    for (Task task : i.getTasks()) {
        out.printf("%-40s%-40s\n", "Query", task.getCommandText());
    }

    out.flush();
}

From source file:org.powertac.producer.fossil.SteamPlantTest.java

@Test
public void dataGenerateOutputGraph() throws IOException {
    double adjustmentSpeed = 10000;
    double variance = 2000;
    double time = (200000 - 500000) / (signum(200000 - 500000) * adjustmentSpeed);

    Curve output = new Curve();
    output.add(0, 500000);/*  ww w.ja va 2  s.co m*/
    output.add(time, 200000);
    output.add(time + 10, 200000);
    Random r = new Random();
    new File("data/").mkdir();
    PrintWriter fw = new PrintWriter("data/dataFossilOutput.txt");
    for (int i = 0; i < 60; i++) {
        fw.printf("%d,%f%n", i, output.value(i - 5) + r.nextGaussian() * variance);
    }
    fw.close();
}

From source file:org.openhab.binding.astro.internal.bus.PlanetPublisher.java

/**
 * Returns the minute:second string for the minutes number.
 *//*  www  .ja v  a2s . co m*/
private String durationToString(long minutes) {
    long hours = minutes / 60;
    minutes -= hours * 60;

    StringWriter sw = new StringWriter();
    PrintWriter writer = new PrintWriter(sw);

    writer.printf("%02d:%02d", hours, minutes);

    writer.flush();
    return sw.getBuffer().toString();
}

From source file:com.aliyun.openservices.odps.console.commands.DescribeResourceCommand.java

@Override
public void run() throws OdpsException, ODPSConsoleException {
    Odps odps = getCurrentOdps();/*ww w.ja v  a  2 s .  c o m*/
    if (!(odps.resources().exists(projectName, resourceName))) {
        throw new ODPSConsoleException("Resource not found : " + resourceName);
    }
    Resource r = odps.resources().get(projectName, resourceName);

    PrintWriter out = new PrintWriter(System.out);

    out.printf("%-40s%-40s\n", "Name", r.getName());
    out.printf("%-40s%-40s\n", "Owner", r.getOwner());
    out.printf("%-40s%-40s\n", "Type", r.getType());
    if (r.getType() == Resource.Type.TABLE) {
        TableResource tr = (TableResource) r;
        String tableSource = tr.getSourceTable().getProject() + "." + tr.getSourceTable().getName();
        if (tr.getSourceTablePartition() != null) {
            tableSource += " partition(" + tr.getSourceTablePartition().toString() + ")";
        }
        out.printf("%-40s%-40s\n", "SourceTableName", tableSource);
    }
    out.printf("%-40s%-40s\n", "Comment", r.getComment());
    out.printf("%-40s%-40s\n", "CreatedTime", DATE_FORMAT.format(r.getCreatedTime()));
    out.printf("%-40s%-40s\n", "LastModifiedTime", DATE_FORMAT.format(r.getLastModifiedTime()));
    out.flush();
}

From source file:cn.vlabs.duckling.vwb.service.dml.html2dml.ParseHtmlEmbed.java

@Override
public void printAttribute(Element e, Html2DmlEngine html2dmlengine) {
    PrintWriter writer = html2dmlengine.getM_out();
    for (String attr : ATTRIBUTE_NAMES) {
        String attrValue = e.getAttributeValue(attr);
        if (StringUtils.isNotBlank(attrValue)) {
            writer.printf(" %s=\"%s\"", attr, e.getAttributeValue(attr));
        }/*from w  w w  .  ja va2  s.com*/
    }

    String srcValue = e.getAttributeValue(ATTRIBUTE_SRC);
    if (srcValue != null) {
        String dmlSrc = html2dmlengine.findAttachment(srcValue, html2dmlengine);
        if (dmlSrc != null) {
            writer.printf(" %s=\"%s\"", "dmlsrc", dmlSrc);
        } else {
            writer.printf(" %s=\"%s\"", "src", srcValue);
        }
    }
}

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

public void saveValue(PrintWriter aPW, FieldRange aFieldRange) throws IOException {
    if (aFieldRange.getType() == Field.Type.Text) {
        String singleString = StrUtl.collapseToSingle(aFieldRange.getItems(), aFieldRange.getDelimiterChar());
        aPW.printf(">%s</%s>%n", StringEscapeUtils.escapeXml10(singleString), RANGE_NODE_NAME);
    } else {//from  w  ww .  jav  a2  s  .c  o m
        IOXML.writeAttrNameValue(aPW, "min", aFieldRange.getMinString());
        IOXML.writeAttrNameValue(aPW, "max", aFieldRange.getMaxString());
        aPW.printf("/>%n");
    }
}

From source file:com.example.HelloLicenseServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html; charset=UTF-8");
    UserService userService = UserServiceFactory.getUserService();
    PrintWriter output = response.getWriter();
    String url = request.getRequestURI();

    if (userService.isUserLoggedIn()) {
        // Provide a logout path.
        User user = userService.getCurrentUser();
        output.printf("<strong>%s</strong> | <a href=\"%s\">Sign out</a><br><br>", user.getEmail(),
                userService.createLogoutURL(url));

        try {// www  . j a v a 2  s  .  c om
            // Send a signed request for the user's license state.
            OAuthConsumer oauth = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
            oauth.setTokenWithSecret(TOKEN, TOKEN_SECRET);
            URLConnection http = new URL(
                    String.format(URL, APP_ID, URLEncoder.encode(user.getFederatedIdentity(), "UTF-8")))
                            .openConnection();
            oauth.sign(http);
            http.connect();

            // Convert the response from the license server to a string.
            BufferedReader input = new BufferedReader(new InputStreamReader(http.getInputStream()));
            String file = "";
            for (String line; (line = input.readLine()) != null; file += line)
                ;
            input.close();

            // Parse the string as JSON and display the license state.
            JSONObject json = new JSONObject(file);
            output.printf("Hello <strong>%s</strong> license!",
                    "YES".equals(json.get("result"))
                            ? "FULL".equals(json.get("accessLevel")) ? "full" : "free trial"
                            : "no");
        } catch (Exception exception) {
            // Dump any error.
            output.printf("Oops! <strong>%s</strong>", exception.getMessage());
        }
    } else { // The user isn't logged in.
        // Prompt for login.
        output.printf("<a href=\"%s\">Sign in</a>", userService.createLoginURL(url, null,
                "https://www.google.com/accounts/o8/id", new HashSet<String>()));
    }
}

From source file:com.silverware.ipdswizzler.EvernoteExporter.java

/**
 * Print a single memo./*from  w ww .j a va  2  s  .  c  o m*/
 * 
 * @param printWriter
 * @param memo
 * @param index
 */
private void printMemo(PrintWriter printWriter, Memo memo, int index) {
    printWriter.println("<note>");

    String title = memo.getTitle();
    String content = memo.getContent();
    String[] tags = memo.getTags();

    if (title != null) {
        printWriter.printf("<title>%s</title>\n", StringEscapeUtils.escapeHtml4(title), index);
    }

    printWriter.print(
            "<content><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note>");

    if (content != null) {
        printContentAsHtml(printWriter, content);
    }

    printWriter.println("</en-note>]]></content>");

    if (tags != null) {
        for (int tagIndex = 0; tagIndex < tags.length; tagIndex++) {
            printWriter.printf("<tag>%s</tag>\n", StringEscapeUtils.escapeHtml4(tags[tagIndex]));
        }
    }

    printWriter.println("</note>");
}