Class HttpDownloader

java.lang.Object
com.dua3.gradle.jdkprovider.provision.HttpDownloader

public final class HttpDownloader extends Object
Simple HTTP downloader with timeouts and basic retry for transient failures.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpDownloader(int connectTimeoutMs, int readTimeoutMs, int retries)
    Constructs an instance of the HttpDownloader class with specified configuration parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    downloadTo(URI uri, Path targetFile)
    Downloads the content from the specified URI to the target file path.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpDownloader

      public HttpDownloader(int connectTimeoutMs, int readTimeoutMs, int retries)
      Constructs an instance of the HttpDownloader class with specified configuration parameters.
      Parameters:
      connectTimeoutMs - the timeout in milliseconds for establishing the HTTP connection
      readTimeoutMs - the timeout in milliseconds for waiting to read data from the HTTP connection
      retries - the maximum number of retries to perform for transient failures; must be zero or greater
  • Method Details

    • downloadTo

      public Path downloadTo(URI uri, Path targetFile) throws IOException, InterruptedException
      Downloads the content from the specified URI to the target file path. If the target file's parent directory does not exist, it will be created. The method retries the download up to the configured number of retries in case of transient failures.
      Parameters:
      uri - the URI from which the content will be downloaded
      targetFile - the path to the file where the downloaded content will be saved
      Returns:
      the path to the target file containing the downloaded content
      Throws:
      IOException - if an I/O error occurs during the download, including HTTP errors
      InterruptedException - if the operation is interrupted