CompletableFuture<Void> downloadIfNecessary(ResourceToDownload resourceToDownload) {
    return CompletableFuture.runAsync(RunnableThatThrows.wrap(() -> {
      LogUtil.setStage("download", resourceToDownload.id);
      long existingSize = FileUtils.size(resourceToDownload.output);
      try {
        resourceToDownload.metadata.complete(httpHeadFollowRedirects(resourceToDownload.url, 0));
      } catch (Exception e) {
        resourceToDownload.metadata.completeExceptionally(e);
        throw e;
      }
      Path tmpPath = resourceToDownload.tmpPath();
      try {
        var metadata = resourceToDownload.metadata.get();
        if (metadata.size.orElse(-1) == existingSize) {
          LOGGER.info("Skipping {}: {} already up-to-date", resourceToDownload.id, resourceToDownload.output);
          return;
        }
        String redirectInfo = metadata.canonicalUrl.equals(resourceToDownload.url) ? "" :
          " (redirected to " + metadata.canonicalUrl + ")";
        LOGGER.info("Downloading {}{} to {}", resourceToDownload.url, redirectInfo, resourceToDownload.output);
        FileUtils.delete(resourceToDownload.output);
        FileUtils.createParentDirectories(resourceToDownload.output);
        FileUtils.delete(tmpPath);
        FileUtils.deleteOnExit(tmpPath);
        if (metadata.size.isPresent()) {
          diskSpaceCheck.addDisk(tmpPath, metadata.size.getAsLong(), resourceToDownload.id);
        }
        diskSpaceCheck.checkAgainstLimits(config.force(), false);
        httpDownload(resourceToDownload, tmpPath);
        Files.move(tmpPath, resourceToDownload.output);
        LOGGER.info("Finished downloading {} to {}", resourceToDownload.url, resourceToDownload.output);
      } catch (Exception e) { // NOSONAR
        LOGGER.error("Error downloading {} to {}", resourceToDownload.url, resourceToDownload.output, e);
        throw e;
      } finally {
        FileUtils.delete(tmpPath);
      }
    }), executor);
  }
Starts downloading all resources in parallel, logging progress until complete.

@throws IllegalStateException if an error occurs downloading any resource, will be thrown after all resources
                              finish
planetiler-core/src/main/java/com/onthegomap/planetiler/util/Downloader.java