@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
Methods
Future<?> download(String, Path, String, ExecutorService, HttpClient)Downloads a file asynchronously and verifies its SHA-1 checksum.Future<?> download(String, Path, String, ExecutorService, HttpClient, LongConsumer)boolean download(String, Path, String)Downloads a single file and checks if the sha1 values matchboolean download(String, Path, String, HttpClient)boolean download(String, Path, String, HttpClient, LongConsumer)Future<?> downloadWithoutSha1(String, Path, ExecutorService, HttpClient, LongConsumer)Downloads a file async without checksum verification, for files that come without a SHA-1
Existing not empty files are skippedvoid downloadWithoutSha1(String, Path, HttpClient, LongConsumer)Downloads a single file without checksum verification, for files that come without a SHA-1
Existing not empty files are skippedHttpRequest prepareClientRequest(String, String)Creates a download request from a version manifest.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 |
|---|
url | String | The download URL |
path | Path | Target file path |
expectedSha1 | String | Expected SHA-1 checksum |
pool | ExecutorService | Executor service used for the download task |
client | HttpClient | HTTP client used for the request |
| Returns |
|---|
Future<?> | A Future representing the download task |
public static boolean download(String url, Path path, String expectedSha1)
Downloads a single file and checks if the sha1 values match
| Parameters |
|---|
url | String | The url to download from |
path | Path | The path to save the file to |
expectedSha1 | String | The expected sha1 value of the file |
| Returns |
|---|
boolean | True 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 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 |
|---|
url | String | The download URL |
path | Path | Target file path |
pool | ExecutorService | Executor service used for the download task |
client | HttpClient | HTTP client used for the request |
progressConsumer | LongConsumer | Receives 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 |
|---|
url | String | The url to download from |
path | Path | The path to save the file to |
client | HttpClient | HTTP client used for the request |
progressConsumer | LongConsumer | Receives the number of bytes read for each chunk |
| Throws |
|---|
RuntimeException | If the download fails; when the server does not answer with HTTP 200 the cause is an HttpException |