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

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

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

PrintWriter.format介绍

[英]Formats args according to the format string format, and writes the result to this stream. This method uses the user's default locale. See "Be wary of the default locale". If automatic flushing is enabled then the buffer is flushed as well.
[中]根据格式字符串格式格式化参数,并将结果写入此流。此方法使用用户的默认区域设置。请参阅“{$0$}”。如果启用自动刷新,则缓冲区也会被刷新。

代码示例

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

@Override
void printf( String format, Object... args )
{
  out.format( format, args );
}

代码示例来源:origin: groovy/groovy-core

public PrintWriter format(String format, Object... args) {
  getResponseWriter().format(format, args);
  return this;
}
public PrintWriter format(Locale l, String format,  Object... args) {

代码示例来源:origin: groovy/groovy-core

public PrintWriter format(Locale l, String format,  Object... args) {
    getResponseWriter().format(l, format, args);
    return this;
  }
};

代码示例来源:origin: spring-projects/spring-session

@Override
public PrintWriter format(Locale l, String format, Object... args) {
  return this.delegate.format(l, format, args);
}

代码示例来源:origin: spring-projects/spring-session

@Override
public PrintWriter format(String format, Object... args) {
  return this.delegate.format(format, args);
}

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

/**
 * Prints a formatted string. The behavior of this method is the same as
 * this writer's {@code #format(Locale, String, Object...)} method.
 *
 * @param l
 *            the locale used in the method. No localization will be applied
 *            if {@code l} is {@code null}.
 * @param format the format string (see {@link java.util.Formatter#format})
 * @param args
 *            the list of arguments passed to the formatter. If there are
 *            more arguments than required by {@code format},
 *            additional arguments are ignored.
 * @return this writer.
 * @throws IllegalFormatException
 *             if the format string is illegal or incompatible with the
 *             arguments, if there are not enough arguments or if any other
 *             error regarding the format string or arguments is detected.
 * @throws NullPointerException if {@code format == null}
 */
public PrintWriter printf(Locale l, String format, Object... args) {
  return format(l, format, args);
}

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

/**
 * Prints a formatted string. The behavior of this method is the same as
 * this writer's {@code #format(String, Object...)} method.
 *
 * <p>The {@code Locale} used is the user's default locale.
 * See "<a href="../util/Locale.html#default_locale">Be wary of the default locale</a>".
 *
 * @param format the format string (see {@link java.util.Formatter#format})
 * @param args
 *            the list of arguments passed to the formatter. If there are
 *            more arguments than required by {@code format},
 *            additional arguments are ignored.
 * @return this writer.
 * @throws IllegalFormatException
 *             if the format string is illegal or incompatible with the
 *             arguments, if there are not enough arguments or if any other
 *             error regarding the format string or arguments is detected.
 * @throws NullPointerException if {@code format == null}
 */
public PrintWriter printf(String format, Object... args) {
  return format(format, args);
}

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

/**
 * Formats {@code args} according to the format string {@code format}, and writes the result
 * to this stream. This method uses the user's default locale.
 * See "<a href="../util/Locale.html#default_locale">Be wary of the default locale</a>".
 * If automatic flushing is enabled then the buffer is flushed as well.
 *
 * @param format the format string (see {@link java.util.Formatter#format})
 * @param args
 *            the list of arguments passed to the formatter. If there are
 *            more arguments than required by {@code format},
 *            additional arguments are ignored.
 * @return this writer.
 * @throws IllegalFormatException
 *             if the format string is illegal or incompatible with the
 *             arguments, if there are not enough arguments or if any other
 *             error regarding the format string or arguments is detected.
 * @throws NullPointerException if {@code format == null}
 */
public PrintWriter format(String format, Object... args) {
  return format(Locale.getDefault(), format, args);
}

代码示例来源:origin: Tencent/tinker

try {
  writer = new PrintWriter(new FileOutputStream(outputFullFilename));
  writer.format("package %s;\n\n", packageName);
  writer.println("public final class R {\n");
  for (RType rType : rTypeResourceMap.keySet()) {
    writer.format("  public static final class %s {\n", rType.toString());
    for (com.tencent.tinker.build.aapt.RDotTxtEntry rDotTxtEntry : rTypeResourceMap.get(rType)) {
      writer.format("    public static%s%s %s=%s;\n", isFinal ? " final " : " ", rDotTxtEntry.idType, rDotTxtEntry.name, rDotTxtEntry.idValue.trim());

代码示例来源:origin: ACRA/acra

@Override
  protected void write(OutputStream outputStream, @NonNull Pair<String, List<Uri>> content) throws IOException {
    final PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, ACRAConstants.UTF8));
    writer.append(SECTION_START)
        .format(CONTENT_DISPOSITION, "ACRA_REPORT", "")
        .format(CONTENT_TYPE, contentType)
        .append(NEW_LINE)
        .append(content.first);
    for (Uri uri : content.second) {
      try {
        String name = UriUtils.getFileNameFromUri(context, uri);
        writer.append(SECTION_START)
            .format(CONTENT_DISPOSITION, "ACRA_ATTACHMENT", name)
            .format(CONTENT_TYPE, UriUtils.getMimeType(context, uri))
            .append(NEW_LINE)
            .flush();
        UriUtils.copyFromUri(context, outputStream, uri);
      } catch (FileNotFoundException e) {
        ACRA.log.w("Not sending attachment", e);
      }
    }
    writer.append(MESSAGE_END).flush();
  }
}

代码示例来源:origin: graphql-java/graphql-java

private TypePrinter<GraphQLUnionType> unionPrinter() {
  return (out, type, visibility) -> {
    if (isIntrospectionType(type)) {
      return;
    }
    printComments(out, type, "");
    out.format("union %s%s = ", type.getName(), directivesString(type.getDirectives()));
    List<GraphQLOutputType> types = type.getTypes()
        .stream()
        .sorted(Comparator.comparing(GraphQLOutputType::getName))
        .collect(toList());
    for (int i = 0; i < types.size(); i++) {
      GraphQLOutputType objectType = types.get(i);
      if (i > 0) {
        out.format(" | ");
      }
      out.format("%s", objectType.getName());
    }
    out.format("\n\n");
  };
}

代码示例来源:origin: graphql-java/graphql-java

private TypePrinter<GraphQLEnumType> enumPrinter() {
  return (out, type, visibility) -> {
    if (isIntrospectionType(type)) {
      return;
    }
    printComments(out, type, "");
    out.format("enum %s%s {\n", type.getName(), directivesString(type.getDirectives()));
    List<GraphQLEnumValueDefinition> values = type.getValues()
        .stream()
        .sorted(Comparator.comparing(GraphQLEnumValueDefinition::getName))
        .collect(toList());
    for (GraphQLEnumValueDefinition enumValueDefinition : values) {
      printComments(out, enumValueDefinition, "  ");
      out.format("  %s%s\n", enumValueDefinition.getName(), directivesString(enumValueDefinition.getDirectives()));
    }
    out.format("}\n\n");
  };
}

代码示例来源:origin: graphql-java/graphql-java

out.format("schema {\n");
if (queryType != null) {
  out.format("  query: %s\n", queryType.getName());
  out.format("  mutation: %s\n", mutationType.getName());
  out.format("  subscription: %s\n", subscriptionType.getName());
out.format("}\n\n");

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

public void writeSVMLightFormat(PrintWriter writer) {
 for (RVFDatum<L, F> datum : this) {
  writer.print(this.labelIndex.indexOf(datum.label()));
  Counter<F> features = datum.asFeaturesCounter();
  for (F feature : features.keySet()) {
   double count = features.getCount(feature);
   writer.format(Locale.ENGLISH, " %s:%f", this.featureIndex.indexOf(feature), count);
  }
  writer.println();
 }
}

代码示例来源:origin: graphql-java/graphql-java

private TypePrinter<GraphQLInputObjectType> inputObjectPrinter() {
  return (out, type, visibility) -> {
    if (isIntrospectionType(type)) {
      return;
    }
    printComments(out, type, "");
    out.format("input %s%s {\n", type.getName(), directivesString(type.getDirectives()));
    visibility.getFieldDefinitions(type)
        .stream()
        .sorted(Comparator.comparing(GraphQLInputObjectField::getName))
        .forEach(fd -> {
          printComments(out, fd, "  ");
          out.format("  %s: %s",
              fd.getName(), typeString(fd.getType()));
          Object defaultValue = fd.getDefaultValue();
          if (defaultValue != null) {
            String astValue = printAst(defaultValue, fd.getType());
            out.format(" = %s", astValue);
          }
          out.format(directivesString(fd.getDirectives()));
          out.format("\n");
        });
    out.format("}\n\n");
  };
}

代码示例来源:origin: spring-projects/spring-session

@Test
public void printWriterFormatStringObjectVargs() throws Exception {
  String format = "format";
  Object[] args = new Object[] { "1" };
  this.response.getWriter().format(format, args);
  verify(this.writer).format(format, args);
}

代码示例来源:origin: spring-projects/spring-session

@Test
public void printWriterFormatLocaleStringObjectVargs() throws Exception {
  Locale l = Locale.US;
  String format = "format";
  Object[] args = new Object[] { "1" };
  this.response.getWriter().format(l, format, args);
  verify(this.writer).format(l, format, args);
}

代码示例来源:origin: graphql-java/graphql-java

private TypePrinter<GraphQLInterfaceType> interfacePrinter() {
  return (out, type, visibility) -> {
    if (isIntrospectionType(type)) {
      return;
    }
    printComments(out, type, "");
    out.format("interface %s%s {\n", type.getName(), directivesString(type.getDirectives()));
    visibility.getFieldDefinitions(type)
        .stream()
        .sorted(Comparator.comparing(GraphQLFieldDefinition::getName))
        .forEach(fd -> {
          printComments(out, fd, "  ");
          out.format("  %s%s: %s%s\n",
              fd.getName(), argsString(fd.getArguments()), typeString(fd.getType()), directivesString(fd.getDirectives()));
        });
    out.format("}\n\n");
  };
}

代码示例来源:origin: graphql-java/graphql-java

private TypePrinter<GraphQLObjectType> objectPrinter() {
  return (out, type, visibility) -> {
    if (isIntrospectionType(type)) {
      return;
    }
    printComments(out, type, "");
    if (type.getInterfaces().isEmpty()) {
      out.format("type %s%s {\n", type.getName(), directivesString(type.getDirectives()));
    } else {
      Stream<String> interfaceNames = type.getInterfaces()
          .stream()
          .map(GraphQLType::getName)
          .sorted(Comparator.naturalOrder());
      out.format("type %s implements %s%s {\n",
          type.getName(),
          interfaceNames.collect(joining(" & ")),
          directivesString(type.getDirectives()));
    }
    visibility.getFieldDefinitions(type)
        .stream()
        .sorted(Comparator.comparing(GraphQLFieldDefinition::getName))
        .forEach(fd -> {
          printComments(out, fd, "  ");
          out.format("  %s%s: %s%s\n",
              fd.getName(), argsString(fd.getArguments()), typeString(fd.getType()), directivesString(fd.getDirectives()));
        });
    out.format("}\n\n");
  };
}

代码示例来源:origin: graphql-java/graphql-java

private TypePrinter<GraphQLScalarType> scalarPrinter() {
  return (out, type, visibility) -> {
    if (!options.isIncludeScalars()) {
      return;
    }
    boolean printScalar;
    if (ScalarInfo.isStandardScalar(type)) {
      printScalar = false;
      //noinspection RedundantIfStatement
      if (options.isIncludeExtendedScalars() && !ScalarInfo.isGraphqlSpecifiedScalar(type)) {
        printScalar = true;
      }
    } else {
      printScalar = true;
    }
    if (printScalar) {
      printComments(out, type, "");
      out.format("scalar %s%s\n\n", type.getName(), directivesString(type.getDirectives()));
    }
  };
}

相关文章