private void httpDownload(ResourceToDownload resource, Path tmpPath)
    throws ExecutionException, InterruptedException {
    var metadata = resource.metadata().get();
    String canonicalUrl = metadata.canonicalUrl();
    record Range(long start, long end) {}
    List<Range> chunks = new ArrayList<>();
    boolean ranges = metadata.acceptRange && config.downloadThreads() > 1;
    long fileSize = metadata.size.orElse(Long.MAX_VALUE);
    long chunkSize = ranges ? chunkSizeBytes : fileSize;
    for (long start = 0; start < fileSize; start += chunkSize) {
      long end = Math.min(start + chunkSize, fileSize);
      chunks.add(new Range(start, end));
    }
    FileUtils.setLength(tmpPath, metadata.size.orElse(1));
    Semaphore perFileLimiter = new Semaphore(config.downloadThreads());
    Worker.joinFutures(chunks.stream().map(range -> CompletableFuture.runAsync(RunnableThatThrows.wrap(() -> {
      LogUtil.setStage("download", resource.id);
      perFileLimiter.acquire();
      var counter = resource.progress.counterForThread();
      try (
        var fc = FileChannel.open(tmpPath, WRITE);
        var inputStream = (ranges || range.start > 0) ?
          openStreamRange(canonicalUrl, range.start, range.end) :
          openStream(canonicalUrl);
      ) {
        long offset = range.start;
        byte[] buffer = new byte[16384];
        int read;
        while (offset < range.end && (read = inputStream.read(buffer, 0, 16384)) >= 0) {
          counter.incBy(read);
          if (rateLimiter != null) {
            rateLimiter.acquire(read);
          }
          int position = 0;
          int remaining = read;
          while (remaining > 0) {
            int written = fc.write(ByteBuffer.wrap(buffer, position, remaining), offset);
            if (written <= 0) {
              throw new IOException("Failed to write to " + tmpPath);
            }
            position += written;
            remaining -= written;
            offset += written;
          }
        }
        if (offset < range.end && range.end != Long.MAX_VALUE) {
          throw new IllegalStateException("Unexpected EOF at " + offset + " expecting " + range.end);
        }
      } finally {
        perFileLimiter.release();
      }
    }), executor)).toArray(CompletableFuture[]::new)).get();
  }
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