java.io.PrintWriter.printf()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中java.io.PrintWriter.printf()方法的一些代码示例,展示了PrintWriter.printf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintWriter.printf()方法的具体详情如下:
包路径:java.io.PrintWriter
类名称:PrintWriter
方法名:printf

PrintWriter.printf介绍

[英]Prints a formatted string. The behavior of this method is the same as this writer's #format(String, Object...) method.

The Locale used is the user's default locale. See "Be wary of the default locale".
[中]打印格式化的字符串。此方法的行为与此编写器的#格式(字符串、对象…)相同方法
使用的区域设置是用户的默认区域设置。请参阅“{$0$}”。

代码示例

代码示例来源:origin: apache/flink

@Override
  public void dump(OutputStream output) {
    try (PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(output, UTF_8))) {

      for (Long value : histogramStatistics.getValues()) {
        printWriter.printf("%d%n", value);
      }
    }
  }
}

代码示例来源:origin: remkop/picocli

private void printUnmatchedArgsBindingList(List<UnmatchedArgsBinding> unmatchedArgsBindings, PrintWriter pw, String indent) {
  pw.printf("%sUnmatchedArgsBindings:", indent);
  pw.println(unmatchedArgsBindings.isEmpty() ? " []" : "");
  for (UnmatchedArgsBinding unmatched : unmatchedArgsBindings) {
    pw.printf("%sgetter: %s%n", indent + "- ", unmatched.getter());
    pw.printf("%ssetter: %s%n", indent + "  ", unmatched.setter());
  }
}

代码示例来源:origin: oracle/helidon

/**
 * Writes the values of the snapshot to the given stream.
 *
 * @param output an output stream
 */
@Override
public void dump(OutputStream output) {
  final PrintWriter out = new PrintWriter(new OutputStreamWriter(output, UTF_8));
  try {
    for (long value : values) {
      out.printf("%d%n", value);
    }
  } finally {
    out.close();
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

private void report(long timestamp, String name, String header, String line, Object... values) {
  try {
    final File file = csvFileProvider.getFile(directory, name);
    final boolean fileAlreadyExists = file.exists();
    if (fileAlreadyExists || file.createNewFile()) {
      try (PrintWriter out = new PrintWriter(new OutputStreamWriter(
          new FileOutputStream(file, true), UTF_8))) {
        if (!fileAlreadyExists) {
          out.println("t," + header);
        }
        out.printf(locale, String.format(locale, "%d" + separator + "%s%n", timestamp, line), values);
      }
    }
  } catch (IOException e) {
    LOGGER.warn("Error writing to {}", name, e);
  }
}

代码示例来源:origin: prestodb/presto

/**
 * Get the stringly representation of footprint table
 *
 * @return footprint table
 */
public String toFootprint() {
  StringWriter sw = new StringWriter();
  PrintWriter pw = new PrintWriter(sw);
  pw.println(name + " instance footprint:");
  pw.printf(" %9s %9s %9s   %s%n", "COUNT", "AVG", "SUM", "DESCRIPTION");
  for (Class<?> key : getClasses()) {
    int count = getClassCounts().count(key);
    int size = getClassSizes().count(key);
    pw.printf(" %9d %9d %9d   %s%n", count, size / count, size, key.getName());
  }
  pw.printf(" %9d %9s %9d   %s%n", totalCount(), "", totalSize(), "(total)");
  pw.println();
  pw.close();
  return sw.toString();
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static void writeConllFile(String outFile, List<CoreMap> sentences, List<DependencyTree> trees)
{
 try
 {
  PrintWriter output = IOUtils.getPrintWriter(outFile);
  for (int i = 0; i < sentences.size(); i++)
  {
   CoreMap sentence = sentences.get(i);
   DependencyTree tree = trees.get(i);
   List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
   for (int j = 1, size = tokens.size(); j <= size; ++j)
   {
    CoreLabel token = tokens.get(j - 1);
    output.printf("%d\t%s\t_\t%s\t%s\t_\t%d\t%s\t_\t_%n",
      j, token.word(), token.tag(), token.tag(),
      tree.getHead(j), tree.getLabel(j));
   }
   output.println();
  }
  output.close();
 }
 catch (Exception e) {
  throw new RuntimeIOException(e);
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

@Override
public void saveToFilename(String s) {
 PrintWriter bw = null;
 try {
  bw = IOUtils.getPrintWriter(s);
  for (int i = 0, size = indexSize; i < size; i++) {
   E o = get(i);
   if (o != null) {
    bw.printf("%d=%s%n", i, o.toString());
   }
  }
  bw.close();
 } catch (IOException e) {
  e.printStackTrace();
 } finally {
  if (bw != null) {
   bw.close();
  }
 }
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static void printCounter(TwoDimensionalCounter<String,String> cnt,
                String fname) {
 try {
  PrintWriter pw = new PrintWriter(new PrintStream(new FileOutputStream(new File(fname)),false,"UTF-8"));
  for(String key : cnt.firstKeySet()) {
   for(String val : cnt.getCounter(key).keySet()) {
    pw.printf("%s\t%s\t%d%n", key, val, (int) cnt.getCount(key, val));
   }
  }
  pw.close();
 } catch (UnsupportedEncodingException e) {
  e.printStackTrace();
 } catch (FileNotFoundException e) {
  e.printStackTrace();
 }
}

代码示例来源:origin: org.springframework.boot/spring-boot

private String getDescription(BeanNotOfRequiredTypeException ex) {
  StringWriter description = new StringWriter();
  PrintWriter printer = new PrintWriter(description);
  printer.printf(
      "The bean '%s' could not be injected as a '%s' because it is a "
          + "JDK dynamic proxy that implements:%n",
      ex.getBeanName(), ex.getRequiredType().getName());
  for (Class<?> requiredTypeInterface : ex.getRequiredType().getInterfaces()) {
    printer.println("\t" + requiredTypeInterface.getName());
  }
  return description.toString();
}

代码示例来源:origin: prestodb/presto

PrintWriter pw = new PrintWriter(sw);
pw.println(name + " object externals:");
pw.printf(" %16s %10s %-" + typeLen + "s %-30s %s%n", "ADDRESS", "SIZE", "TYPE", "PATH", "VALUE");
for (long addr : addresses()) {
  Object obj = record(addr).obj();
    pw.printf(" %16x %10d %-" + typeLen + "s %-30s %s%n", last, addr - last, "(something else)", "(somewhere else)", "(something else)");
    pw.printf(" %16x %10d %-" + typeLen + "s %-30s %s%n", last, addr - last, "**** OVERLAP ****", "**** OVERLAP ****", "**** OVERLAP ****");
  pw.printf(" %16x %10d %-" + typeLen + "s %-30s %s%n", addr, size, obj.getClass().getName(), record(addr).path(), VMSupport.safeToString(obj));
  last = addr + size;
pw.println();
pw.close();
return sw.toString();

代码示例来源:origin: line/armeria

@Override
  public void dump(OutputStream output) {
    // Do not close this writer in order to keep output stream open.
    final PrintWriter p = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
    p.printf("Dump of %s:%n", this);
    for (int i = 0; i < values.size(); i++) {
      p.printf("<%d> %s%n", i, values.get(i));
    }
    p.flush();
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

pwOut.println("GUESS TREEBANK:");
pwOut.println(guessTreebank.textualSummary());
pwOut.println("GOLD TREEBANK:");
pwOut.println(goldTreebank.textualSummary());
  pwOut.printf("Yield mismatch gold: %d tokens vs. guess: %d tokens (lines: gold %d guess %d)%n", goldYield.size(), guessYield.size(), goldLineId, guessLineId);
  skippedGuessTrees++;
  continue;
pwOut.println("================================================================================");
if(skippedGuessTrees != 0) pwOut.printf("%s %d guess trees\n", "Unable to evaluate", skippedGuessTrees);
metric.display(true, pwOut);
pwOut.println();
pwOut.close();

代码示例来源:origin: remkop/picocli

private static void printCommandElementDefClose(PrintWriter pw, Object userObject, String indent) {
  if (userObject instanceof Method || userObject instanceof ExecutableElement) {
    String full = (userObject).toString();
    pw.print(full.substring(full.indexOf(')')));
    pw.println(" {");
    pw.println(indent + "    // TODO implement commandSpec");
    pw.println(indent + "}");
  } else {
    pw.printf("%s}%n", indent);
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

pw.printf("%s\t%d%n", wordType,(int) vocab.getCount(wordType));
pw.close();

代码示例来源:origin: jenkinsci/jenkins

out = new PrintWriter(new OutputStreamWriter(rsp.getOutputStream()));
} catch (IllegalStateException e) {
  out = rsp.getWriter();
out.printf(
  "<html><head>" +
  "<meta http-equiv='refresh' content='1;url=%1$s'/>" +
  cause.report(out);
out.printf(
  "-->\n\n"+
  "</body></html>");
out.close();

代码示例来源:origin: jenkinsci/jenkins

try (PrintWriter pw = new PrintWriter(writer)) {
  pw.printf("%s grabbed %s from queue but %s %s. ", getName(), workUnit, owner.getDisplayName(), reason);
  if (owner.getTerminatedBy().isEmpty()) {
    pw.print("No termination trace available.");
  } else {
    pw.println("Termination trace follows:");
    for (Computer.TerminationRequest request : owner.getTerminatedBy()) {
      Functions.printStackTrace(request, pw);

代码示例来源:origin: prestodb/presto

public static String vmDetails() {
  StringWriter sw = new StringWriter();
  PrintWriter out = new PrintWriter(sw);
  out.println("Running " + (ADDRESS_SIZE * 8) + "-bit " + VM_NAME + " VM.");
  if (USE_COMPRESSED_REFS)
    out.println("Using compressed references with " + COMPRESSED_REF_SHIFT + "-bit shift.");
  out.println("Objects are " + OBJ_ALIGNMENT + " bytes aligned.");
  out.printf("%-19s: %d, %d, %d, %d, %d, %d, %d, %d, %d [bytes]%n",
      "Field sizes by type",
      REF_SIZE,
  );
  out.printf("%-19s: %d, %d, %d, %d, %d, %d, %d, %d, %d [bytes]%n",
      "Array element sizes",
      U.arrayIndexScale(Object[].class),
  );
  out.close();
  return sw.toString();

代码示例来源:origin: io.dropwizard.metrics/metrics-core

/**
   * Writes the values of the snapshot to the given stream.
   *
   * @param output an output stream
   */
  @Override
  public void dump(OutputStream output) {
    try (PrintWriter out = new PrintWriter(new OutputStreamWriter(output, UTF_8))) {
      for (long value : values) {
        out.printf("%d%n", value);
      }
    }
  }
}

代码示例来源:origin: marytts/marytts

out.println("# This file lists the features and their weights to be used for\n" + "# creating the MARY features file.\n"
    + "# The same file can also be used to override weights in a run-time system.\n"
    + "# Three sections are distinguished: Byte-valued, Short-valued, and\n" + "# Continuous features.\n" + "#\n"
    + "# and all unit feature files for individual database utterances.\n"
    + "# THIS FILE WAS GENERATED AUTOMATICALLY");
out.println();
out.println("ByteValuedFeatureProcessors");
List<String> getValuesOf10 = new ArrayList<String>();
getValuesOf10.add("phone");
    break;
  out.printf("%d linear | %s\n", featureValue, featureName);
out.close();

代码示例来源:origin: remkop/picocli

private void printPositionalList(List<PositionalParamSpec> positionals, PrintWriter pw, String indent) {
  pw.printf("%sPositionalParams:", indent);
  pw.println(positionals.isEmpty() ? " []" : "");
  for (PositionalParamSpec positional : positionals) {
    printPositional(positional, pw, indent);
  }
}
private void printPositional(PositionalParamSpec positional, PrintWriter pw, String indent) {

相关文章