public class Downloader extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT
Default connection timeout in milliseconds when using
FileUtils.copyURLToFile(URL, File, int, int) |
static int |
DEFAULT_READ_TIMEOUT
Default read timeout in milliseconds when using
FileUtils.copyURLToFile(URL, File, int, int) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkMD5OfFile(String targetMD5,
File file)
Check the MD5 of the specified file
|
static void |
download(String name,
URL url,
File f,
String targetMD5,
int maxTries)
As per
download(String, URL, File, String, int, int, int) with the connection and read timeouts
set to their default values - DEFAULT_CONNECTION_TIMEOUT and DEFAULT_READ_TIMEOUT respectively |
static void |
download(String name,
URL url,
File f,
String targetMD5,
int maxTries,
int connectionTimeout,
int readTimeout)
Download the specified URL to the specified file, and verify that the target MD5 matches
|
static void |
downloadAndExtract(String name,
URL url,
File f,
File extractToDir,
String targetMD5,
int maxTries)
As per
downloadAndExtract(String, URL, File, File, String, int, int, int) with the connection and read timeouts
* set to their default values - DEFAULT_CONNECTION_TIMEOUT and DEFAULT_READ_TIMEOUT respectively |
static void |
downloadAndExtract(String name,
URL url,
File f,
File extractToDir,
String targetMD5,
int maxTries,
int connectionTimeout,
int readTimeout)
Download the specified URL to the specified file, verify that the MD5 matches, and then extract it to the specified directory.
Note that the file must be an archive, with the correct file extension: .zip, .jar, .tar.gz, .tgz or .gz |
public static final int DEFAULT_CONNECTION_TIMEOUT
FileUtils.copyURLToFile(URL, File, int, int)public static final int DEFAULT_READ_TIMEOUT
FileUtils.copyURLToFile(URL, File, int, int)public static void download(String name, URL url, File f, String targetMD5, int maxTries) throws IOException
download(String, URL, File, String, int, int, int) with the connection and read timeouts
set to their default values - DEFAULT_CONNECTION_TIMEOUT and DEFAULT_READ_TIMEOUT respectivelyIOExceptionpublic static void download(String name, URL url, File f, String targetMD5, int maxTries, int connectionTimeout, int readTimeout) throws IOException
name - Name (mainly for providing useful exceptions)url - URL to downloadf - Destination filetargetMD5 - Expected MD5 for filemaxTries - Maximum number of download attempts before failing and throwing an exceptionconnectionTimeout - connection timeout in milliseconds, as used by FileUtils.copyURLToFile(URL, File, int, int)readTimeout - read timeout in milliseconds, as used by FileUtils.copyURLToFile(URL, File, int, int)IOException - If an error occurs during downloadingpublic static void downloadAndExtract(String name, URL url, File f, File extractToDir, String targetMD5, int maxTries) throws IOException
downloadAndExtract(String, URL, File, File, String, int, int, int) with the connection and read timeouts
* set to their default values - DEFAULT_CONNECTION_TIMEOUT and DEFAULT_READ_TIMEOUT respectivelyIOExceptionpublic static void downloadAndExtract(String name, URL url, File f, File extractToDir, String targetMD5, int maxTries, int connectionTimeout, int readTimeout) throws IOException
name - Name (mainly for providing useful exceptions)url - URL to downloadf - Destination fileextractToDir - Destination directory to extract all filestargetMD5 - Expected MD5 for filemaxTries - Maximum number of download attempts before failing and throwing an exceptionconnectionTimeout - connection timeout in milliseconds, as used by FileUtils.copyURLToFile(URL, File, int, int)readTimeout - read timeout in milliseconds, as used by FileUtils.copyURLToFile(URL, File, int, int)IOException - If an error occurs during downloadingpublic static boolean checkMD5OfFile(String targetMD5, File file) throws IOException
targetMD5 - Expected MD5file - File to checkIOExceptionCopyright © 2021. All rights reserved.