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

The following are Jave code examples for showing how to use format() 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: Reer   File: DefaultMultiCauseException.java   View Source Code Vote up 7 votes
@Override
public void printStackTrace(PrintWriter printWriter) {
    if (causes.size() <= 1) {
        super.printStackTrace(printWriter);
        return;
    }

    hideCause.set(true);
    try {
        super.printStackTrace(printWriter);
        for (int i = 0; i < causes.size(); i++) {
            Throwable cause = causes.get(i);
            printWriter.format("Cause %s: ", i + 1);
            cause.printStackTrace(printWriter);
        }
    } finally {
        hideCause.set(false);
    }
}
 
Example 2
Project: Reer   File: XmlTransformer.java   View Source Code Vote up 7 votes
private void printNode(Node node, Writer writer) {
    final PrintWriter printWriter = new PrintWriter(writer);
    if (GUtil.isTrue(publicId)) {
        printWriter.format("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">%n", node.name(), publicId, systemId);
    }
    IndentPrinter indentPrinter = new IndentPrinter(printWriter, indentation) {
        @Override
        public void println() {
            printWriter.println();
        }
    };
    XmlNodePrinter nodePrinter = new XmlNodePrinter(indentPrinter);
    nodePrinter.setPreserveWhitespace(true);
    nodePrinter.print(node);
    printWriter.flush();
}
 
Example 3
Project: enigma-vk   File: MappingsWriter.java   View Source Code Vote up 7 votes
private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException {
	if (classMapping.getDeobfName() == null) {
		out.format("%sCLASS %s\n", getIndent(depth), classMapping.getObfFullName());
	} else {
		out.format("%sCLASS %s %s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getDeobfName());
	}
	
	for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) {
		write(out, innerClassMapping, depth + 1);
	}
	
	for (FieldMapping fieldMapping : sorted(classMapping.fields())) {
		write(out, fieldMapping, depth + 1);
	}
	
	for (MethodMapping methodMapping : sorted(classMapping.methods())) {
		write(out, methodMapping, depth + 1);
	}
}
 
Example 4
Project: openjdk-jdk10   File: GNUStyleOptions.java   View Source Code Vote up 7 votes
private static void printHelp0(PrintWriter out, boolean printExtra) {
    out.format("%s%n", Main.getMsg("main.help.preopt"));
    for (OptionType type : OptionType.values()) {
        boolean typeHeadingWritten = false;

        for (Option o : recognizedOptions) {
            if (!o.type.equals(type))
                continue;
            String name = o.aliases[0].substring(1); // there must always be at least one name
            name = name.charAt(0) == '-' ? name.substring(1) : name;
            if (o.isHidden() || name.equals("h")) {
                continue;
            }
            if (o.isExtra() && !printExtra) {
                continue;
            }
            if (!typeHeadingWritten) {
                out.format("%n%s%n", Main.getMsg("main.help.opt." + type.name));
                typeHeadingWritten = true;
            }
            out.format("%s%n", Main.getMsg("main.help.opt." + type.name + "." + name));
        }
    }
    out.format("%n%s%n%n", Main.getMsg("main.help.postopt"));
}
 
Example 5
Project: enigma-vk   File: MappingsWriter.java   View Source Code Vote up 6 votes
private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException {
	if (methodMapping.getDeobfName() == null) {
		out.format("%sMETHOD %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfSignature());
	} else {
		out.format("%sMETHOD %s %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature());
	}
	
	for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) {
		write(out, argumentMapping, depth + 1);
	}
}
 
Example 6
Project: openjdk-jdk10   File: ModuleAnalyzer.java   View Source Code Vote up 6 votes
private void printModuleDescriptor(PrintWriter out, Module module) {
    ModuleDescriptor descriptor = module.descriptor();
    out.format("%s (%s)%n", descriptor.name(), module.location());

    if (descriptor.name().equals(JAVA_BASE))
        return;

    out.println("  [Module descriptor]");
    descriptor.requires()
        .stream()
        .sorted(Comparator.comparing(ModuleDescriptor.Requires::name))
        .forEach(req -> out.format("    requires %s;%n", req));
}
 
Example 7
Project: Android_Code_Arbiter   File: XssServlet5.java   View Source Code Vote up 6 votes
public void testFormatUnsafe(PrintWriter pw, String input1,HttpServletRequest req) {
    pw.format(req.getLocale(), "%s", input1);
    pw.format("%s", input1);
    pw.format("%s %s", "SAFE", input1);
    pw.format("%s %s %s", "SAFE", "SAFE", input1);
    pw.format("%s %s %s %s", "SAFE", "SAFE", input1, "SAFE");
    pw.format(input1, "<== the actual format string can be alter");
}
 
Example 8
Project: dremio-oss   File: QlikAppMessageBodyGenerator.java   View Source Code Vote up 6 votes
private void writeFields(PrintWriter pw, String fieldType, Collection<ViewFieldType> fields) throws IOException {
  if (!fields.isEmpty()) {
    pw.format("  %s ", fieldType);

    Joiner.on(", ").appendTo(pw, Iterables.transform(fields, FIELD_TO_NAME));
    pw.println();
  }
}
 
Example 9
Project: omero-ms-queue   File: ImportOutputFormatter.java   View Source Code Vote up 5 votes
private static void field(PrintWriter out, String name, Object value) {
    out.format("%s: %s%n", name, value);
}
 
Example 10
Project: enigma-vk   File: MappingsWriter.java   View Source Code Vote up 5 votes
private void write(PrintWriter out, FieldMapping fieldMapping, int depth) throws IOException {
	out.format("%sFIELD %s %s %s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfType().toString());
}
 
Example 11
Project: enigma-vk   File: MappingsWriter.java   View Source Code Vote up 5 votes
private void write(PrintWriter out, ArgumentMapping argumentMapping, int depth) throws IOException {
	out.format("%sARG %d %s\n", getIndent(depth), argumentMapping.getIndex(), argumentMapping.getName());
}
 
Example 12
Project: openjdk-jdk10   File: ModuleDotGraph.java   View Source Code Vote up 5 votes
public void printNode(PrintWriter out, String node, String color, String group) {
    out.format("  \"%s\" [fontcolor=\"%s\", group=%s];%n",
               node, color, group);
}
 
Example 13
Project: openjdk-jdk10   File: JdepsWriter.java   View Source Code Vote up 5 votes
DotFileFormatter(PrintWriter writer, Archive archive) {
    this.writer = writer;
    this.name = archive.getName();
    writer.format("digraph \"%s\" {%n", name);
    writer.format("    // Path: %s%n", archive.getPathName());
}
 
Example 14
Project: openjdk-jdk10   File: JdepsWriter.java   View Source Code Vote up 5 votes
SummaryDotFile(PrintWriter writer, Analyzer.Type type) {
    this.writer = writer;
    this.type = type;
    writer.format("digraph \"summary\" {%n");
}
 
Example 15
Project: openjdk-jdk10   File: ModuleInfoBuilder.java   View Source Code Vote up 5 votes
private void printModuleInfo(PrintWriter writer, ModuleDescriptor md) {
    writer.format("%smodule %s {%n", open ? "open " : "", md.name());

    Map<String, Module> modules = configuration.getModules();

    // first print requires
    Set<Requires> reqs = md.requires().stream()
        .filter(req -> !req.name().equals("java.base") && req.modifiers().isEmpty())
        .collect(Collectors.toSet());
    reqs.stream()
        .sorted(Comparator.comparing(Requires::name))
        .forEach(req -> writer.format("    requires %s;%n",
                                      toString(req.modifiers(), req.name())));
    if (!reqs.isEmpty()) {
        writer.println();
    }

    // requires transitive
    reqs = md.requires().stream()
             .filter(req -> !req.name().equals("java.base") && !req.modifiers().isEmpty())
             .collect(Collectors.toSet());
    reqs.stream()
        .sorted(Comparator.comparing(Requires::name))
        .forEach(req -> writer.format("    requires %s;%n",
                                      toString(req.modifiers(), req.name())));
    if (!reqs.isEmpty()) {
        writer.println();
    }

    if (!open) {
        md.exports().stream()
          .peek(exp -> {
              if (exp.isQualified())
                  throw new InternalError(md.name() + " qualified exports: " + exp);
              })
          .sorted(Comparator.comparing(Exports::source))
          .forEach(exp -> writer.format("    exports %s;%n", exp.source()));

        if (!md.exports().isEmpty()) {
            writer.println();
        }
    }

    md.provides().stream()
      .sorted(Comparator.comparing(Provides::service))
      .map(p -> p.providers().stream()
                 .map(impl -> "        " + impl.replace('$', '.'))
                 .collect(joining(",\n",
                                  String.format("    provides %s with%n",
                                                p.service().replace('$', '.')),
                                  ";")))
                 .forEach(writer::println);

    if (!md.provides().isEmpty()) {
        writer.println();
    }
    writer.println("}");
}
 
Example 16
Project: openjdk-jdk10   File: GNUStyleOptions.java   View Source Code Vote up 5 votes
static void printCompatHelp(PrintWriter out) {
    out.format("%s%n", Main.getMsg("usage.compat"));
}
 
Example 17
Project: openjdk-jdk10   File: GNUStyleOptions.java   View Source Code Vote up 5 votes
static void printUsageTryHelp(PrintWriter out) {
    out.format("%s%n", Main.getMsg("main.usage.summary.try"));
}
 
Example 18
Project: openjdk-jdk10   File: GNUStyleOptions.java   View Source Code Vote up 5 votes
static void printVersion(PrintWriter out) {
    out.format("%s %s%n", "jar", System.getProperty("java.version"));
}
 
Example 19
Project: Android_Code_Arbiter   File: XssServlet5.java   View Source Code Vote up 5 votes
public void testFormatSafe(PrintWriter pw, String input1,HttpServletRequest req) {
    pw.format(req.getLocale(), "Data : %s", "Constant data");
    pw.format("%s", "SAFE");
    pw.format("%s %s", "SAFE","SAFE");
    pw.format("%s %s %s", "SAFE","SAFE","SAFE");
}