private static void downloadFile(final URL fileUrl,
                                     final Path destFilename,
                                     final HttpClient httpClient) {
        try {
            final HttpGet httpGet = new HttpGet(fileUrl.toString());
            httpClient.execute(httpGet, response -> {
                try (final InputStream inputStream = response.getEntity().getContent()) {
                    // Create a temp file as the download destination to avoid overwriting an existing file.
                    final Path tempFile = Files.createTempFile("stroom", "download");
                    try (final OutputStream fos = new BufferedOutputStream(Files.newOutputStream(tempFile))) {
                        StreamUtil.streamToStream(inputStream, fos);
                    }

                    // Atomically move the downloaded file to the destination so that
                    // concurrent tests don't overwrite the file.
                    try {
                        Files.move(tempFile, destFilename);
                    } catch (FileAlreadyExistsException e) {
                        // Don't see why we should get here as the methods are synchronized
                        LOGGER.warn("Unable to move {} to {} as file already exists, ignoring the error.",
                                tempFile.toAbsolutePath().normalize(),
                                destFilename.toAbsolutePath().normalize(),
                                e);
                    }
                }
                return response.getCode();
            });
        } catch (final IOException e) {
            throw new UncheckedIOException(String.format("Error downloading url %s to %s",
                    fileUrl.toString(), FileUtil.getCanonicalPath(destFilename)), e);
        }
    }
synchronized to avoid multiple test threads downloading the same pack concurrently
Don't have to worry about other JVM as this method is called under lock on a single common file.
stroom-test-common/src/main/java/stroom/test/common/util/test/ContentPackZipDownloader.java