- final ListeningExecutorService service = MoreExecutors.listeningDecorator(ForkJoinPool.commonPool());
- final List<ListenableFuture<Void>> parentFutures = new ArrayList<>(dirs.keySet().size());
- for (Entry<Path, Collection<GenerationTask>> entry : dirs.asMap().entrySet()) {
- parentFutures.add(service.submit(() -> {
- Files.createDirectories(entry.getKey());
- return null;
- }));
- }
-
- try {
- Futures.whenAllComplete(parentFutures).call(() -> {
- for (ListenableFuture<Void> future : parentFutures) {
- Futures.getDone(future);
- }
- return null;
- }, MoreExecutors.directExecutor()).get();
- } catch (InterruptedException e) {
- throw new IOException("Interrupted while creating parent directories", e);
- } catch (ExecutionException e) {
- LOG.debug("Failed to create parent directories", e);
- Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
- throw new IOException("Failed to create parent directories", e);
- }
+ dirs.keySet().parallelStream().forEach(path -> {
+ try {
+ Files.createDirectories(path);
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to create " + path, e);
+ }
+ });