Class FileDownloadUtils
java.lang.Object
org.biojava.nbio.structure.io.util.FileDownloadUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCopy the content of file src to dst TODO since java 1.7 this is provided in java.nio.file.Filesstatic voiddeleteDirectory(String dir) Recursively delete a folder & contentsstatic voiddeleteDirectory(Path dir) Recursively delete a folder & contentsstatic voiddownloadFile(URL url, File destination) Download the content provided at URL url and store the result to a local file, using a temp file to cache the content in case something goes wrong in downloadstatic StringexpandUserHome(String file) Expands ~ in paths to the user's home directory.static Stringstatic Stringstatic voidstatic booleanPings a HTTP URL.static URLConnectionprepareURLConnection(String url, int timeout) PrepareURLConnectionwith customised timeouts.static StringtoUnixPath(String path) Converts path to Unix convention and adds a terminating slash if it was omitted
-
Constructor Details
-
FileDownloadUtils
public FileDownloadUtils()
-
-
Method Details
-
copy
Copy the content of file src to dst TODO since java 1.7 this is provided in java.nio.file.Files- Parameters:
src-dst-- Throws:
IOException
-
getFileExtension
-
getFilePrefix
-
downloadFile
Download the content provided at URL url and store the result to a local file, using a temp file to cache the content in case something goes wrong in download- Parameters:
url-destination-- Throws:
IOException
-
toUnixPath
Converts path to Unix convention and adds a terminating slash if it was omitted- Parameters:
path- original platform dependent path- Returns:
- path in Unix convention
- Since:
- 3.2
-
expandUserHome
Expands ~ in paths to the user's home directory.This does not work for some special cases for paths: Other users' homes (~user/...), and Tilde expansion within the path (/.../~/...)
- Parameters:
file-- Returns:
-
ping
Pings a HTTP URL. This effectively sends a HEAD request and returnstrueif the response code is in the 200-399 range.- Parameters:
url- The HTTP URL to be pinged.timeout- The timeout in millis for both the connection timeout and the response read timeout. Note that the total timeout is effectively two times the given timeout.- Returns:
trueif the given HTTP URL has returned response code 200-399 on a HEAD request within the given timeout, otherwisefalse.
-
prepareURLConnection
PrepareURLConnectionwith customised timeouts.- Parameters:
url- The URLtimeout- The timeout in millis for both the connection timeout and the response read timeout. Note that the total timeout is effectively two times the given timeout.Example of code.
UrlConnection conn = prepareURLConnection("http://www.google.com/", 20000); conn.connect(); conn.getInputStream();NB. User should execute connect() method before getting input stream. - Returns:
- Throws:
IOException
-
deleteDirectory
Recursively delete a folder & contents- Parameters:
dir- directory to delete- Throws:
IOException
-
deleteDirectory
Recursively delete a folder & contents- Parameters:
dir- directory to delete- Throws:
IOException
-
main
-