@Test public void testReadUnNestedPath() throws IOException { Path unNestedFolder = _folder.newFolder("unNestedDirectory").toPath(); Set<Path> expected = new HashSet<>(); expected.add(unNestedFolder.resolve("test1.cfg")); expected.add(unNestedFolder.resolve("test2.cfg")); expected.add(unNestedFolder.resolve("test3.cfg")); for (Path path : expected) { path.getParent().toFile().mkdir(); assertThat(path.toFile().createNewFile(), is(true)); } Set<Path> actual = readAllFiles(unNestedFolder, LOGGER).keySet(); assertThat(expected, equalTo(actual)); }
static SortedMap<Path, String> readAllFiles(Path directory, BatfishLogger logger) throws IOException { try (Stream<Path> paths = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) { return paths .filter(Files::isRegularFile) .filter(path -> !path.getFileName().toString().startsWith(".")) .map( path -> { logger.debugf("Reading: \"%s\"\n", path); try (InputStream inputStream = Files.newInputStream(path)) { return new SimpleEntry<>(path, decodeStreamAndAppendNewline(inputStream)); } catch (IOException e) { throw new UncheckedIOException(String.format("Failed to read file: %s", path), e); } }) .collect( ImmutableSortedMap.toImmutableSortedMap( Ordering.natural(), SimpleEntry::getKey, SimpleEntry::getValue)); } }
CliUtils { static SortedMap<Path, String> readAllFiles(Path directory, BatfishLogger logger) throws IOException { try (Stream<Path> paths = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) { return paths .filter(Files::isRegularFile) .filter(path -> !path.getFileName().toString().startsWith(".")) .map( path -> { logger.debugf("Reading: \"%s\"\n", path); try (InputStream inputStream = Files.newInputStream(path)) { return new SimpleEntry<>(path, decodeStreamAndAppendNewline(inputStream)); } catch (IOException e) { throw new UncheckedIOException(String.format("Failed to read file: %s", path), e); } }) .collect( ImmutableSortedMap.toImmutableSortedMap( Ordering.natural(), SimpleEntry::getKey, SimpleEntry::getValue)); } } }
CliUtils { static SortedMap<Path, String> readAllFiles(Path directory, BatfishLogger logger) throws IOException { try (Stream<Path> paths = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) { return paths .filter(Files::isRegularFile) .filter(path -> !path.getFileName().toString().startsWith(".")) .map( path -> { logger.debugf("Reading: \"%s\"\n", path); try (InputStream inputStream = Files.newInputStream(path)) { return new SimpleEntry<>(path, decodeStreamAndAppendNewline(inputStream)); } catch (IOException e) { throw new UncheckedIOException(String.format("Failed to read file: %s", path), e); } }) .collect( ImmutableSortedMap.toImmutableSortedMap( Ordering.natural(), SimpleEntry::getKey, SimpleEntry::getValue)); } } private  CliUtils(); }
CliUtils { static SortedMap<Path, String> readAllFiles(Path directory, BatfishLogger logger) throws IOException { try (Stream<Path> paths = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) { return paths .filter(Files::isRegularFile) .filter(path -> !path.getFileName().toString().startsWith(".")) .map( path -> { logger.debugf("Reading: \"%s\"\n", path); try (InputStream inputStream = Files.newInputStream(path)) { return new SimpleEntry<>(path, decodeStreamAndAppendNewline(inputStream)); } catch (IOException e) { throw new UncheckedIOException(String.format("Failed to read file: %s", path), e); } }) .collect( ImmutableSortedMap.toImmutableSortedMap( Ordering.natural(), SimpleEntry::getKey, SimpleEntry::getValue)); } } private  CliUtils();  }
CliUtils { static SortedMap<Path, String> readAllFiles(Path directory, BatfishLogger logger) throws IOException { try (Stream<Path> paths = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) { return paths .filter(Files::isRegularFile) .filter(path -> !path.getFileName().toString().startsWith(".")) .map( path -> { logger.debugf("Reading: \"%s\"\n", path); try (InputStream inputStream = Files.newInputStream(path)) { return new SimpleEntry<>(path, decodeStreamAndAppendNewline(inputStream)); } catch (IOException e) { throw new UncheckedIOException(String.format("Failed to read file: %s", path), e); } }) .collect( ImmutableSortedMap.toImmutableSortedMap( Ordering.natural(), SimpleEntry::getKey, SimpleEntry::getValue)); } } private  CliUtils();   }