classstableSource
@API(status = STABLE)
public class DownloadHelper

Download helper for downloading files and verifying SHA-1 checksums. Recently moved over from the Launch module, be careful.

Constructors

public DownloadHelper()

Methods

public static Future<?> download(
    String url,
    Path path,
    String expectedSha1,
    ExecutorService pool,
    HttpClient client
)
Downloads a file asynchronously and verifies its SHA-1 checksum. Existing files with a matching checksum are skipped.
Parameters
urlStringThe download URL
pathPathTarget file path
expectedSha1StringExpected SHA-1 checksum
poolExecutorServiceExecutor service used for the download task
clientHttpClientHTTP client used for the request
Returns
Future<?>A Future representing the download task
public static Future<?> download(
    String url,
    Path path,
    String expectedSha1,
    ExecutorService pool,
    HttpClient client,
    LongConsumer progressConsumer
)
Parameters
urlString
pathPath
expectedSha1String
poolExecutorService
clientHttpClient
progressConsumerLongConsumer
Returns
Future<?>
public static boolean download(String url, Path path, String expectedSha1)
Downloads a single file and checks if the sha1 values match
Parameters
urlStringThe url to download from
pathPathThe path to save the file to
expectedSha1StringThe expected sha1 value of the file
Returns
booleanTrue if the file was downloaded or already exists with the correct sha1, false if the file has a wrong sha1 value after downloading
public static boolean download(String url, Path path, String expectedSha1, HttpClient client)
Parameters
urlString
pathPath
expectedSha1String
clientHttpClient
Returns
boolean
public static boolean download(
    String url,
    Path path,
    String expectedSha1,
    HttpClient client,
    LongConsumer progressConsumer
)
Parameters
urlString
pathPath
expectedSha1String
clientHttpClient
progressConsumerLongConsumer
Returns
boolean
public static Future<?> downloadWithoutSha1(
    String url,
    Path path,
    ExecutorService pool,
    HttpClient client,
    LongConsumer progressConsumer
)
Downloads a file async without checksum verification, for files that come without a SHA-1 Existing not empty files are skipped
Parameters
urlStringThe download URL
pathPathTarget file path
poolExecutorServiceExecutor service used for the download task
clientHttpClientHTTP client used for the request
progressConsumerLongConsumerReceives the number of bytes read for each chunk
Returns
Future<?>A Future representing the download task
public static void downloadWithoutSha1(
    String url,
    Path path,
    HttpClient client,
    LongConsumer progressConsumer
)
Downloads a single file without checksum verification, for files that come without a SHA-1 Existing not empty files are skipped
Parameters
urlStringThe url to download from
pathPathThe path to save the file to
clientHttpClientHTTP client used for the request
progressConsumerLongConsumerReceives the number of bytes read for each chunk
Throws
RuntimeExceptionIf the download fails; when the server does not answer with HTTP 200 the cause is an HttpException
public static HttpRequest prepareClientRequest(String manifestUrl, String type) throws HttpException, IOException
Creates a download request from a version manifest.
Parameters
manifestUrlStringURL of the version manifest
typeStringDownload type, usually client or server
Returns
HttpRequestThe prepared download request
Throws
HttpExceptionIf the manifest request fails
IOExceptionIf the manifest cannot be read