Java Code Examples for java.io.PrintWriter.printf()

The following are Jave code examples for showing how to use printf() of the java.io.PrintWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hadoop   File: CLI.java   View Source Code Vote up 6 votes
@Private
public void displayJobList(JobStatus[] jobs, PrintWriter writer) {
  writer.println("Total jobs:" + jobs.length);
  writer.printf(headerPattern, "JobId", "State", "StartTime", "UserName",
    "Queue", "Priority", "UsedContainers",
    "RsvdContainers", "UsedMem", "RsvdMem", "NeededMem", "AM info");
  for (JobStatus job : jobs) {
    int numUsedSlots = job.getNumUsedSlots();
    int numReservedSlots = job.getNumReservedSlots();
    int usedMem = job.getUsedMem();
    int rsvdMem = job.getReservedMem();
    int neededMem = job.getNeededMem();
    writer.printf(dataPattern,
        job.getJobID().toString(), job.getState(), job.getStartTime(),
        job.getUsername(), job.getQueue(), 
        job.getPriority().name(),
        numUsedSlots < 0 ? UNAVAILABLE : numUsedSlots,
        numReservedSlots < 0 ? UNAVAILABLE : numReservedSlots,
        usedMem < 0 ? UNAVAILABLE : String.format(memPattern, usedMem),
        rsvdMem < 0 ? UNAVAILABLE : String.format(memPattern, rsvdMem),
        neededMem < 0 ? UNAVAILABLE : String.format(memPattern, neededMem),
        job.getSchedulingInfo());
  }
  writer.flush();
}
 
Example 2
Project: AlgoCS   File: HeatingMain_1457.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
    Scanner x = new Scanner(System.in);
    short n = x.nextShort();
    double s = 0;
    for (int i = 0; i < n; i++) {
        s += x.nextInt();
    }
    writer.printf("%.6f", s / n);
    writer.close();
}
 
Example 3
Project: openjdk-jdk10   File: ActionSet.java   View Source Code Vote up 6 votes
private List<PatternAction> getPatternActions(PrintWriter log,
                                              Properties p, String key) {
    String[] tools = getTools(log, p, key);
    List<PatternAction> result = new ArrayList<>(tools.length);
    for (String tool : tools) {
        try {
            PatternAction action = new PatternAction(
                    Utils.prependPrefix(name, tool), tool, p);
            result.add(action);
        } catch (Exception e) {
            log.printf("ERROR: %s cannot be created : %s %n",
                    tool, e.getMessage());
            e.printStackTrace(log);
        }
    }
    return result;
}
 
Example 4
Project: openjdk-jdk10   File: ActionSet.java   View Source Code Vote up 6 votes
private List<SimpleAction> getSimpleActions(PrintWriter log, Properties p,
                                            String key) {
    String[] tools = getTools(log, p, key);
    List<SimpleAction> result = new ArrayList<>(tools.length);
    for (String tool : tools) {
        try {
            SimpleAction action = new SimpleAction(
                    Utils.prependPrefix(name, tool), tool, p);
            result.add(action);
        } catch (Exception e) {
            log.printf("ERROR: %s cannot be created : %s %n",
                    tool, e.getMessage());
            e.printStackTrace(log);
        }
    }
    return result;
}
 
Example 5
Project: openjdk-jdk10   File: PluginGenerator.java   View Source Code Vote up 6 votes
protected static void createImports(PrintWriter out, List<GeneratedPlugin> plugins) {
    out.printf("import jdk.vm.ci.meta.ResolvedJavaMethod;\n");
    out.printf("import org.graalvm.compiler.serviceprovider.ServiceProvider;\n");
    out.printf("\n");
    out.printf("import org.graalvm.compiler.nodes.ValueNode;\n");
    out.printf("import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;\n");
    out.printf("import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;\n");
    out.printf("import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;\n");
    out.printf("import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;\n");
    out.printf("import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory;\n");

    HashSet<String> extra = new HashSet<>();
    for (GeneratedPlugin plugin : plugins) {
        plugin.extraImports(extra);
    }
    if (!extra.isEmpty()) {
        out.printf("\n");
        for (String i : extra) {
            out.printf("import %s;\n", i);
        }
    }
}
 
Example 6
Project: hadoop   File: ReconfigurationServlet.java   View Source Code Vote up 5 votes
private void printHeader(PrintWriter out, String nodeName) {
  out.print("<html><head>");
  out.printf("<title>%s Reconfiguration Utility</title>%n",
             StringEscapeUtils.escapeHtml(nodeName));
  out.print("</head><body>\n");
  out.printf("<h1>%s Reconfiguration Utility</h1>%n",
             StringEscapeUtils.escapeHtml(nodeName));
}
 
Example 7
Project: openjdk-jdk10   File: GeneratedPlugin.java   View Source Code Vote up 5 votes
public void register(PrintWriter out) {
    out.printf("        plugins.register(new %s(", pluginName);
    if (needInjectionProvider) {
        out.printf("injection");
    }
    out.printf("), %s.class, \"%s\"", intrinsicMethod.getEnclosingElement(), intrinsicMethod.getSimpleName());
    if (!intrinsicMethod.getModifiers().contains(Modifier.STATIC)) {
        out.printf(", InvocationPlugin.Receiver.class");
    }
    for (VariableElement arg : intrinsicMethod.getParameters()) {
        out.printf(", %s.class", getErasedType(arg.asType()));
    }
    out.printf(");\n");
}
 
Example 8
Project: metacherchant   File: GraphvizWriter.java   View Source Code Vote up 5 votes
private void printFreqs(PrintWriter out, String label) {
    int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
    for (int i = 0; i + k <= label.length(); i++) {
        String kmer = label.substring(i, i + k);
        int freq = subgraph.get(kmer);
        min = Math.min(min, freq);
        max = Math.max(max, freq);
    }
    out.printf(":%d:%d", min, max);
}
 
Example 9
Project: openjdk-jdk10   File: GeneratedPlugin.java   View Source Code Vote up 5 votes
public void generate(ProcessingEnvironment env, PrintWriter out) {
    out.printf("    //        class: %s\n", intrinsicMethod.getEnclosingElement());
    out.printf("    //       method: %s\n", intrinsicMethod);
    out.printf("    // generated-by: %s\n", getClass().getName());
    out.printf("    private static final class %s extends GeneratedInvocationPlugin {\n", pluginName);
    out.printf("\n");
    out.printf("        @Override\n");
    out.printf("        public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] args) {\n");
    InjectedDependencies deps = createExecute(env, out);
    out.printf("        }\n");

    createPrivateMembers(out, deps);

    out.printf("    }\n");
}
 
Example 10
Project: openjdk-jdk10   File: ActionHelper.java   View Source Code Vote up 5 votes
public ProcessBuilder prepareProcess(PrintWriter log, String app,
                                     String... args) {
    File appBin = findApp(app);
    if (appBin == null) {
        log.printf("ERROR: can't find %s in %s.%n",
                app, Arrays.toString(paths));
        return null;
    }
    List<String> command = new ArrayList<>(args.length + 1);
    command.add(appBin.toString());
    Collections.addAll(command, args);
    return new ProcessBuilder()
            .command(command)
            .directory(workDir.toFile());
}
 
Example 11
Project: openjdk-jdk10   File: GatherProcessInfoTimeoutHandler.java   View Source Code Vote up 5 votes
private void runGatherer(String name, Path workDir, PrintWriter log,
                         PrintWriter out, long pid) {
    try (HtmlPage html = new HtmlPage(out)) {
        ProcessInfoGatherer gatherer = new GathererFactory(
                OS.current().family,
                workDir, log, testJdk.toPath()).getProcessInfoGatherer();
        try (ElapsedTimePrinter timePrinter
                     = new ElapsedTimePrinter(new Stopwatch(), name, log)) {
            gatherer.gatherProcessInfo(html.getRootSection(), pid);
        }
    } catch (Throwable e) {
        log.printf("ERROR: exception in timeout handler %s:", name);
        e.printStackTrace(log);
    }
}
 
Example 12
Project: dremio-oss   File: Node.java   View Source Code Vote up 5 votes
void print(PrintWriter writer, String indent, boolean printChildren) {
  writer.printf("%s%s %s [%s] version %d%n", indent, type, name, fullPath(), getVersion());
  if (printChildren) {
    for (Node child : children) {
      child.print(writer, indent + "  ", true);
    }
  }
}
 
Example 13
Project: argument-reasoning-comprehension-task   File: Step9aFinalDataProvider.java   View Source Code Vote up 5 votes
static void printEntry(PrintWriter pw, String reasonClaimWarrantId, String w0, String w1,
        Integer correctLabelW0orW1, String reasonGist, String annotatedStance, String title,
        String description)
{
    pw.printf(Locale.ENGLISH, "%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s%n", reasonClaimWarrantId, w0, w1,
            correctLabelW0orW1, reasonGist, annotatedStance, title, description);
}
 
Example 14
Project: Prog2   File: E905.java   View Source Code Vote up 5 votes
public static void writeFile(String[] words, File file) throws IOException {
	PrintWriter hp = new PrintWriter(file);
	
	for (int i = 0; i < words.length; i++){
		hp.printf("%s\n", words[i]);
	}
	
	hp.close();
}
 
Example 15
Project: Tarski   File: MailBug.java   View Source Code Vote up 5 votes
/** This method prepares the crash report. */
private static String prepareCrashReport (Thread thread, Throwable ex, String email, String problem) {
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   pw.printf("Alloy Analyzer %s crash report (Build Date = %s)\n", Version.version(), Version.buildDate());
   pw.printf("\n========================= Email ============================\n%s\n", Util.convertLineBreak(email).trim());
   pw.printf("\n========================= Problem ==========================\n%s\n", Util.convertLineBreak(problem).trim());
   pw.printf("\n========================= Thread Name ======================\n%s\n", thread.getName().trim());
   if (ex!=null) pw.printf("\n========================= Stack Trace ======================\n%s\n", dump(ex));
   pw.printf("\n========================= Preferences ======================\n");
   try {
      for(String key: Preferences.userNodeForPackage(Util.class).keys()) {
         String value = Preferences.userNodeForPackage(Util.class).get(key, "");
         pw.printf("%s = %s\n", key.trim(), value.trim());
      }
   } catch(BackingStoreException bse) {
      pw.printf("BackingStoreException occurred: %s\n", bse.toString().trim());
   }
   pw.printf("\n========================= System Properties ================\n");
   pw.println("Runtime.freeMemory() = " + Runtime.getRuntime().freeMemory());
   pw.println("nRuntime.totalMemory() = " + Runtime.getRuntime().totalMemory());
   for(Map.Entry<Object,Object> e: System.getProperties().entrySet()) {
      String k = String.valueOf(e.getKey()), v = String.valueOf(e.getValue());
      pw.printf("%s = %s\n", k.trim(), v.trim());
   }
   pw.printf("\n========================= The End ==========================\n\n");
   pw.close();
   sw.flush();
   return sw.toString();
}
 
Example 16
Project: jol-samples   File: JOLSample_19_Promotion.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws Exception {
    out.println(VM.current().details());

    PrintWriter pw = new PrintWriter(System.out, true);

    Object o = new Object();

    ClassLayout layout = ClassLayout.parseInstance(o);

    long lastAddr = VM.current().addressOf(o);
    pw.printf("Fresh object is at %x%n", lastAddr);

    int moves = 0;
    for (int i = 0; i < 100000; i++) {
        long cur = VM.current().addressOf(o);
        if (cur != lastAddr) {
            moves++;
            pw.printf("*** Move %2d, object is at %x%n", moves, cur);
            out.println(layout.toPrintable());
            lastAddr = cur;
        }

        // make garbage
        for (int c = 0; c < 10000; c++) {
            sink = new Object();
        }
    }

    pw.close();
}
 
Example 17
Project: openjdk-jdk10   File: SimpleSerialization.java   View Source Code Vote up 4 votes
private static PrintWriter printObject(final PrintWriter pw, final Object o) {
    pw.printf("%[email protected]%08x", o.getClass().getName(), System.identityHashCode(o));
    return pw;
}
 
Example 18
Project: openjdk-jdk10   File: GeneratedPlugin.java   View Source Code Vote up 4 votes
protected static void constantArgument(ProcessingEnvironment env, PrintWriter out, InjectedDependencies deps, int argIdx, TypeMirror type, int nodeIdx) {
    if (hasRawtypeWarning(type)) {
        out.printf("            @SuppressWarnings({\"rawtypes\"})\n");
    }
    out.printf("            %s arg%d;\n", getErasedType(type), argIdx);
    out.printf("            if (args[%d].isConstant()) {\n", nodeIdx);
    if (type.equals(resolvedJavaTypeType(env))) {
        out.printf("                arg%d = %s.asJavaType(args[%d].asConstant());\n", argIdx, deps.use(WellKnownDependency.CONSTANT_REFLECTION), nodeIdx);
    } else {
        switch (type.getKind()) {
            case BOOLEAN:
                out.printf("                arg%d = args[%d].asJavaConstant().asInt() != 0;\n", argIdx, nodeIdx);
                break;
            case BYTE:
                out.printf("                arg%d = (byte) args[%d].asJavaConstant().asInt();\n", argIdx, nodeIdx);
                break;
            case CHAR:
                out.printf("                arg%d = (char) args[%d].asJavaConstant().asInt();\n", argIdx, nodeIdx);
                break;
            case SHORT:
                out.printf("                arg%d = (short) args[%d].asJavaConstant().asInt();\n", argIdx, nodeIdx);
                break;
            case INT:
                out.printf("                arg%d = args[%d].asJavaConstant().asInt();\n", argIdx, nodeIdx);
                break;
            case LONG:
                out.printf("                arg%d = args[%d].asJavaConstant().asLong();\n", argIdx, nodeIdx);
                break;
            case FLOAT:
                out.printf("                arg%d = args[%d].asJavaConstant().asFloat();\n", argIdx, nodeIdx);
                break;
            case DOUBLE:
                out.printf("                arg%d = args[%d].asJavaConstant().asDouble();\n", argIdx, nodeIdx);
                break;
            case ARRAY:
            case DECLARED:
                out.printf("                arg%d = %s.asObject(%s.class, args[%d].asJavaConstant());\n", argIdx, deps.use(WellKnownDependency.SNIPPET_REFLECTION), getErasedType(type), nodeIdx);
                break;
            default:
                throw new IllegalArgumentException(type.toString());
        }
    }
    out.printf("            } else {\n");
    out.printf("                return false;\n");
    out.printf("            }\n");
}
 
Example 19
Project: openjdk-jdk10   File: SourceModel.java   View Source Code Vote up 4 votes
protected void generate(PrintWriter pw) {
    pw.printf("%s %s", this.type, this.name);
}
 
Example 20
Project: jdk8u-jdk   File: SimpleSerialization.java   View Source Code Vote up 4 votes
private static PrintWriter printObject(final PrintWriter pw, final Object o) {
    pw.printf("%[email protected]%08x", o.getClass().getName(), System.identityHashCode(o));
    return pw;
}