@Override public long download(boolean resume, DownloadCompleteCallback callback) { if (skipDownloadOnStatus()) return 0; int bytes = 0; File file = new File(toFile); try { long localFileSize = checkLocalFileSizeForResume(resume, file); if (checkServerResponse(localFileSize)) return 0; if (!tryAndGetRemoteSize()) return 0; if (!canHandleDownloadSize()) return 0; checkAndSetDownloadSize(); if (copyBytes(file, in, out)) return 0; checkDowloadCompletion(); downloadTime += finish.getTime() - start.getTime(); } finally { /* in.close() and out.close() */ }
public HttpTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, DownloadCompleteCallback callback, long maxTemplateSizeInBytes, String user, String password, Proxy proxy, ResourceType resourceType) { _storage = storageLayer; this.downloadUrl = downloadUrl; this.toDir = toDir; this.resourceType = resourceType; this.maxTemplateSizeInBytes = maxTemplateSizeInBytes; completionCallback = callback; status = TemplateDownloader.Status.NOT_STARTED; totalBytes = 0; client = new HttpClient(s_httpClientManager); myretryhandler = createRetryTwiceHandler(); try { request = createRequest(downloadUrl); checkTemporaryDestination(toDir); checkProxy(proxy); checkCredentials(user, password); } catch (Exception ex) { errorString = "Unable to start download -- check url? "; status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; s_logger.warn("Exception in constructor -- " + ex.toString()); } catch (Throwable th) { s_logger.warn("throwable caught ", th); } }
public static void main(String[] args) { String url = "http:// dev.mysql.com/get/Downloads/MySQL-5.0/mysql-noinstall-5.0.77-win32.zip/from/http://mirror.services.wisc.edu/mysql/"; try { new java.net.URI(url); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } TemplateDownloader td = new HttpTemplateDownloader(null, url, "/tmp/mysql", null, TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES, null, null, null, null); long bytes = td.download(true, null); if (bytes > 0) { System.out.println("Downloaded (" + bytes + " bytes)" + " in " + td.getDownloadTime() / 1000 + " secs"); } else { System.out.println("Failed download"); } }
td = new MetalinkTemplateDownloader(_storage, url, tmpDir, new Completion(jobId), maxTemplateSizeInBytes); } else if (uri.getScheme().equalsIgnoreCase("http") || uri.getScheme().equalsIgnoreCase("https")) { td = new HttpTemplateDownloader(_storage, url, tmpDir, new Completion(jobId), maxTemplateSizeInBytes, user, password, proxy, resourceType); } else if (uri.getScheme().equalsIgnoreCase("file")) { td = new LocalTemplateDownloader(_storage, url, tmpDir, maxTemplateSizeInBytes, new Completion(jobId));