Package org.nd4j.common.resources
Class Downloader
- java.lang.Object
-
- org.nd4j.common.resources.Downloader
-
public class Downloader extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECTION_TIMEOUTDefault connection timeout in milliseconds when usingFileUtils.copyURLToFile(URL, File, int, int)static intDEFAULT_READ_TIMEOUTDefault read timeout in milliseconds when usingFileUtils.copyURLToFile(URL, File, int, int)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckMD5OfFile(String targetMD5, File file)Check the MD5 of the specified filestatic booleandeleteIfCorrupted(File inputFile, String targetmd5)Check if the input file is corrupted by verifying the target md5 hash.static voiddownload(String name, URL url, File f, String targetMD5, int maxTries)As perdownload(String, URL, File, String, int, int, int)with the connection and read timeouts set to their default values -DEFAULT_CONNECTION_TIMEOUTandDEFAULT_READ_TIMEOUTrespectivelystatic voiddownload(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 matchesstatic voiddownloadAndExtract(String name, URL url, File f, File extractToDir, String targetMD5, int maxTries)As perdownloadAndExtract(String, URL, File, File, String, int, int, int)with the connection and read timeouts * set to their default values -DEFAULT_CONNECTION_TIMEOUTandDEFAULT_READ_TIMEOUTrespectivelystatic voiddownloadAndExtract(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
-
-
-
Field Detail
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT
Default connection timeout in milliseconds when usingFileUtils.copyURLToFile(URL, File, int, int)- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT
public static final int DEFAULT_READ_TIMEOUT
Default read timeout in milliseconds when usingFileUtils.copyURLToFile(URL, File, int, int)- See Also:
- Constant Field Values
-
-
Method Detail
-
download
public static void download(String name, URL url, File f, String targetMD5, int maxTries) throws IOException
As perdownload(String, URL, File, String, int, int, int)with the connection and read timeouts set to their default values -DEFAULT_CONNECTION_TIMEOUTandDEFAULT_READ_TIMEOUTrespectively- Throws:
IOException
-
download
public static void download(String name, URL url, File f, String targetMD5, int maxTries, int connectionTimeout, int readTimeout) throws IOException
Download the specified URL to the specified file, and verify that the target MD5 matches- Parameters:
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 byFileUtils.copyURLToFile(URL, File, int, int)readTimeout- read timeout in milliseconds, as used byFileUtils.copyURLToFile(URL, File, int, int)- Throws:
IOException- If an error occurs during downloading
-
downloadAndExtract
public static void downloadAndExtract(String name, URL url, File f, File extractToDir, String targetMD5, int maxTries) throws IOException
As perdownloadAndExtract(String, URL, File, File, String, int, int, int)with the connection and read timeouts * set to their default values -DEFAULT_CONNECTION_TIMEOUTandDEFAULT_READ_TIMEOUTrespectively- Throws:
IOException
-
downloadAndExtract
public static void downloadAndExtract(String name, URL url, File f, File extractToDir, String targetMD5, int maxTries, int connectionTimeout, int readTimeout) throws IOException
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- Parameters:
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 byFileUtils.copyURLToFile(URL, File, int, int)readTimeout- read timeout in milliseconds, as used byFileUtils.copyURLToFile(URL, File, int, int)- Throws:
IOException- If an error occurs during downloading
-
deleteIfCorrupted
public static boolean deleteIfCorrupted(File inputFile, String targetmd5) throws IOException
Check if the input file is corrupted by verifying the target md5 hash. If corrupted, file is deleted- Parameters:
inputFile- the input file to checktargetmd5- the target md5 to test- Throws:
IOException
-
checkMD5OfFile
public static boolean checkMD5OfFile(String targetMD5, File file) throws IOException
Check the MD5 of the specified file- Parameters:
targetMD5- Expected MD5file- File to check- Returns:
- True if MD5 matches, false otherwise
- Throws:
IOException
-
-