@Test public void testfetchAndSumBodies() throws Exception { try(Fetcher fetcher = new Fetcher()) { fetcher .fetchAndSumBodies("https: .thenAccept(sum -> assertEquals(527801, sum.intValue())) .join(); } }
public CompletableFuture<Integer> fetchAndSumBodies(Path folder) throws IOException { return Files .walk(folder) .filter(Files::isRegularFile) .map(path -> AsyncFiles.readAll(path)) .map(cf -> cf.thenCompose(url -> fetchBodyLength(url))) .reduce((prev, curr) -> prev.thenCombine(curr, (l1, l2) -> l1 + l2)) .get(); }
Fetcher implements AutoCloseable { public CompletableFuture<Integer> fetchAndSumBodies(Path folder) throws IOException { return Files .walk(folder) .filter(Files::isRegularFile) .map(path -> AsyncFiles.readAll(path)) .map(cf -> cf.thenCompose(url -> fetchBodyLength(url))) .reduce((prev, curr) -> prev.thenCombine(curr, (l1, l2) -> l1 + l2)) .get(); } }
Fetcher implements AutoCloseable { public CompletableFuture<Integer> fetchAndSumBodies(Path folder) throws IOException { return Files .walk(folder) .filter(Files::isRegularFile) .map(path -> AsyncFiles.readAll(path)) .map(cf -> cf.thenCompose(url -> fetchBodyLength(url))) .reduce((prev, curr) -> prev.thenCombine(curr, (l1, l2) -> l1 + l2)) .get(); }  }
Fetcher implements AutoCloseable { public CompletableFuture<Integer> fetchAndSumBodies(Path folder) throws IOException { return Files .walk(folder) .filter(Files::isRegularFile) .map(path -> AsyncFiles.readAll(path)) .map(cf -> cf.thenCompose(url -> fetchBodyLength(url))) .reduce((prev, curr) -> prev.thenCombine(curr, (l1, l2) -> l1 + l2)) .get(); }  CompletableFuture<Integer> fetchAndSumBodies(Path folder); CompletableFuture<Integer> fetchAndSumBodies(String...urls); @Override void close(); }
Fetcher implements AutoCloseable { public CompletableFuture<Integer> fetchAndSumBodies(Path folder) throws IOException { return Files .walk(folder) .filter(Files::isRegularFile) .map(path -> AsyncFiles.readAll(path)) .map(cf -> cf.thenCompose(url -> fetchBodyLength(url))) .reduce((prev, curr) -> prev.thenCombine(curr, (l1, l2) -> l1 + l2)) .get(); }  CompletableFuture<Integer> fetchAndSumBodies(Path folder); CompletableFuture<Integer> fetchAndSumBodies(String...urls); @Override void close();  }