@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (cla.getPathIn() == null || file.getFileName().equals(cla.getPathIn())) { verbose("Reading %s", file); String newFile = file.getFileName().toString(); final int lastIndex = newFile.lastIndexOf("."); newFile = lastIndex < 0 ? newFile + FILE_EXT_XML : newFile.substring(0, lastIndex) + FILE_EXT_XML; final Path resolved = file.resolveSibling(newFile); try (final InputStream input = new InputStreamWrapper(Files.newInputStream(file), file.toString()); final OutputStream output = Files.newOutputStream(resolved)) { try { convert(input, output); countOKs.incrementAndGet(); } catch (ConfigurationException | IOException e) { countFails.incrementAndGet(); if (cla.isFailFast()) { throw e; } e.printStackTrace(); } verbose("Wrote %s", resolved); } } return FileVisitResult.CONTINUE; } });
OutputStream getOutputStream() throws IOException { final Path pathOut = cla.getPathOut(); return pathOut == null ? System.out : Files.newOutputStream(pathOut); }
private void verbose(final String template, final Object... args) { if (cla.isVerbose()) { System.err.println(String.format(template, args)); } }
private void run() { if (cla.getRecurseIntoPath() != null) { final AtomicInteger countOKs = new AtomicInteger(); final AtomicInteger countFails = new AtomicInteger(); try { Files.walkFileTree(cla.getRecurseIntoPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) verbose("Reading %s", cla.getPathIn()); try (final InputStream input = getInputStream(); final OutputStream output = getOutputStream()) { convert(input, output); throw new ConfigurationException(e); verbose("Wrote %s", cla.getPathOut());
public static void main(final String[] args) { CommandLine.run(new CommandLineArguments(), System.err, args); }
InputStream getInputStream() throws IOException { final Path pathIn = cla.getPathIn(); return pathIn == null ? System.in : new InputStreamWrapper(Files.newInputStream(pathIn), pathIn.toString()); }
@Override public void run() { if (isHelp()) { CommandLine.usage(this, System.err); return; } new Log4j1ConfigurationConverter(this).run(); }