private DOMMetadataResolver downloadMetadata(final long contentLength, final String url) {
        var numThreads = Runtime.getRuntime().availableProcessors();

        var partSize = contentLength / numThreads;
        var executor = Executors.newFixedThreadPool(numThreads);
        try {
            var destination = Files.createTempFile("idpmetadata", ".xml").toFile();
            LOGGER.debug("Downloading idp metadata to {}", destination.getAbsolutePath());
            var futures = new ArrayList<Future<Void>>();

            for (var i = 0; i < numThreads; i++) {
                var start = i * partSize;
                var end = i == numThreads - 1 ? contentLength - 1 : start + partSize - 1;

                futures.add(executor.submit(() -> {
                    var conn = (HttpURLConnection) new URL(url).openConnection();
                    if (conn instanceof HttpsURLConnection https) {
                        if (hostnameVerifier != null) {
                            https.setHostnameVerifier(hostnameVerifier);
                        }
                        if (sslSocketFactory != null) {
                            https.setSSLSocketFactory(sslSocketFactory);
                        }
                    }
                    conn.setRequestProperty("Range", "bytes=" + start + '-' + end);

                    try (var in = conn.getInputStream(); var out = new RandomAccessFile(destination, "rw")) {
                        out.seek(start);
                        var buffer = new byte[8192];
                        var bytesRead = 0;
                        while ((bytesRead = in.read(buffer)) != -1) {
                            out.write(buffer, 0, bytesRead);
                        }
                    } finally {
                        conn.disconnect();
                    }
                    return null;
                }));
            }

            for (var future : futures) {
                future.get();
            }
            executor.shutdown();

            LOGGER.debug("Finished downloading idp metadata to {}", destination.getAbsolutePath());
            var resource = new FileSystemResource(destination);
            return loadMetadataFromResource(resource);
        } catch (Exception e) {
            throw new TechnicalException("Error downloading idp metadata", e);
        }
    }
Resolve and download idp metadata to form a metadata resolver.
<p>
The resolver supports proxies using {@link Proxy} when fetching metadata over URL resources.

@author Misagh Moayyed
@since 1.7
pac4j-saml/src/main/java/org/pac4j/saml/metadata/SAML2IdentityProviderMetadataResolver.java