public class FileDownloadUtils extends Object
Constructor and Description |
---|
FileDownloadUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
copy(File src,
File dst)
Copy the content of file src to dst TODO since java 1.7 this is provided
in java.nio.file.Files
|
static void |
downloadFile(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 download
|
static String |
expandUserHome(String file)
Expands ~ in paths to the user's home directory.
|
static String |
getFileExtension(File f) |
static String |
getFilePrefix(File f) |
static void |
main(String[] args) |
static boolean |
ping(String url,
int timeout)
Pings a HTTP URL.
|
static URLConnection |
prepareURLConnection(String url,
int timeout)
Prepare
URLConnection with customised timeouts. |
static String |
toUnixPath(String path)
Converts path to Unix convention and adds a terminating slash if it was
omitted
|
public FileDownloadUtils()
public static void copy(File src, File dst) throws IOException
src
- dst
- IOException
public static String getFileExtension(File f)
public static String getFilePrefix(File f)
public static void downloadFile(URL url, File destination) throws IOException
url
- destination
- IOException
public static String toUnixPath(String path)
path
- original platform dependent pathpublic static String expandUserHome(String file)
This does not work for some special cases for paths: Other users' homes (~user/...), and Tilde expansion within the path (/.../~/...)
file
- public static boolean ping(String url, int timeout)
true
if the response code is in the 200-399 range.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.true
if the given HTTP URL has returned response
code 200-399 on a HEAD request within the given timeout, otherwise
false
.public static URLConnection prepareURLConnection(String url, int timeout) throws IOException
URLConnection
with customised timeouts.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();
IOException
Copyright © 2000–2018 BioJava. All rights reserved.