added option to download a file without using the configured proxy

Former-commit-id: 7153a34a12a02a53bf715fe023e820afd42899d2
This commit is contained in:
Jeremy Long
2014-03-08 06:18:44 -05:00
parent d18a36af22
commit 84ecc4c664

View File

@@ -46,14 +46,26 @@ public final class Downloader {
/** /**
* Retrieves a file from a given URL and saves it to the outputPath. * Retrieves a file from a given URL and saves it to the outputPath.
* *
* @param url the URL of the file to download. * @param url the URL of the file to download
* @param outputPath the path to the save the file to. * @param outputPath the path to the save the file to
* @throws DownloadFailedException is thrown if there is an error downloading the file. * @throws DownloadFailedException is thrown if there is an error downloading the file
*/ */
public static void fetchFile(URL url, File outputPath) throws DownloadFailedException { public static void fetchFile(URL url, File outputPath) throws DownloadFailedException {
fetchFile(url, outputPath, true);
}
/**
* Retrieves a file from a given URL and saves it to the outputPath.
*
* @param url the URL of the file to download
* @param outputPath the path to the save the file to
* @param useProxy whether to use the configured proxy when downloading files
* @throws DownloadFailedException is thrown if there is an error downloading the file
*/
public static void fetchFile(URL url, File outputPath, boolean useProxy) throws DownloadFailedException {
HttpURLConnection conn = null; HttpURLConnection conn = null;
try { try {
conn = URLConnectionFactory.createHttpURLConnection(url); conn = URLConnectionFactory.createHttpURLConnection(url, useProxy);
conn.setRequestProperty("Accept-Encoding", "gzip, deflate"); conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.connect(); conn.connect();
} catch (IOException ex) { } catch (IOException ex) {