@Test public void testFormatting() throws IOException { List<Pattern> patterns = Collections.singletonList(Pattern.compile(".+\\.xml")); DocViewFormat format = new DocViewFormat(); assertFalse("malformed.xml is expected to be malformed", format.format(dir, patterns, false).isEmpty()); try (InputStream input = this.getClass().getResourceAsStream("DocViewFormat/formatted.xml")) { final String expected = IOUtils.toString(input, StandardCharsets.UTF_8); final String result = FileUtils.readFileToString(docViewFile, StandardCharsets.UTF_8); assertEquals(expected, result); } assertTrue("malformed.xml is expected to be formatted", format.format(dir, patterns, true).isEmpty()); }
public boolean format(File file, boolean dryRun) throws IOException { CRC32 originalCrc32 = new CRC32(); CRC32 formattedCrc32 = new CRC32(); byte[] formatted = format(file, originalCrc32, formattedCrc32); final boolean changed = originalCrc32.getValue() != formattedCrc32.getValue(); if (changed && !dryRun) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { IOUtils.copy(new ByteArrayInputStream(formatted), out); } } return changed; }
DocViewFormat { public boolean format(File file, boolean dryRun) throws IOException { CRC32 originalCrc32 = new CRC32(); CRC32 formattedCrc32 = new CRC32(); byte[] formatted = format(file, originalCrc32, formattedCrc32); final boolean changed = originalCrc32.getValue() != formattedCrc32.getValue(); if (changed && !dryRun) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { IOUtils.copy(new ByteArrayInputStream(formatted), out); } } return changed; } }
DocViewFormat { public boolean format(File file, boolean dryRun) throws IOException { CRC32 originalCrc32 = new CRC32(); CRC32 formattedCrc32 = new CRC32(); byte[] formatted = format(file, originalCrc32, formattedCrc32); final boolean changed = originalCrc32.getValue() != formattedCrc32.getValue(); if (changed && !dryRun) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { IOUtils.copy(new ByteArrayInputStream(formatted), out); } } return changed; } DocViewFormat(); }
DocViewFormat { public boolean format(File file, boolean dryRun) throws IOException { CRC32 originalCrc32 = new CRC32(); CRC32 formattedCrc32 = new CRC32(); byte[] formatted = format(file, originalCrc32, formattedCrc32); final boolean changed = originalCrc32.getValue() != formattedCrc32.getValue(); if (changed && !dryRun) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { IOUtils.copy(new ByteArrayInputStream(formatted), out); } } return changed; } DocViewFormat(); OutputFormat getXmlOutputFormat(); boolean format(File file, boolean dryRun); List<String> format(File directory, List<Pattern> filenamePatterns, final boolean dryRun); }
DocViewFormat { public boolean format(File file, boolean dryRun) throws IOException { CRC32 originalCrc32 = new CRC32(); CRC32 formattedCrc32 = new CRC32(); byte[] formatted = format(file, originalCrc32, formattedCrc32); final boolean changed = originalCrc32.getValue() != formattedCrc32.getValue(); if (changed && !dryRun) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { IOUtils.copy(new ByteArrayInputStream(formatted), out); } } return changed; } DocViewFormat(); OutputFormat getXmlOutputFormat(); boolean format(File file, boolean dryRun); List<String> format(File directory, List<Pattern> filenamePatterns, final boolean dryRun);  }