}
static void prettyPrint(Collection<String> inputFilenames, String outputFilename, boolean strict,
InputStream stdin, OutputStream stdout)
throws IOException {
JsonFactory factory = new JsonFactory();
factory.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);
if (!strict) {
factory.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
factory.enable(JsonParser.Feature.ALLOW_COMMENTS);
factory.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS);
factory.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS);
factory.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS);
factory.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
}
// Open the output stream and create the Json emitter.
JsonGenerator generator;
File tempOutputFile = null, outputFile = null;
if ("-".equals(outputFilename)) {
generator = factory.createGenerator(stdout, JsonEncoding.UTF8);
} else if (!caseInsensitiveContains(inputFilenames, outputFilename)) {
generator = factory.createGenerator(new File(outputFilename), JsonEncoding.UTF8);
} else {
// Writing to an input file.. use a temp file to stage the output until we're done.
outputFile = new File(outputFilename);
tempOutputFile = getTemporaryFileFor(outputFile);
generator = factory.createGenerator(tempOutputFile, JsonEncoding.UTF8);
}
try {
// Separate top-level objects by a newline in the output.
String newline = System.getProperty("line.separator");
generator.setPrettyPrinter(new DefaultPrettyPrinter(newline));
for (String inputFilename : inputFilenames) {
JsonParser parser;
if ("-".equals(inputFilename)) {
parser = factory.createParser(stdin);
} else {
parser = factory.createParser(new File(inputFilename));
}
try {
while (parser.nextToken() != null) {
generator.copyCurrentStructure(parser);
}