/** * @param job * @param uri * @param dest * @throws LucidException */ private void copy(Progress job, URI uri, URI dest) throws LucidException { if (job != null) { // TRANSLATOR: Progress label for downloading one or more files. job.setSectionName(JSMsg.gettext("Downloading files")); } WebResource wr = new WebResource(uri, proxyHost, proxyPort); wr.copy(dest, job); wr.shutdown(); }
public static int getSize(URI uri, String proxyHost, Integer proxyPort) { try { if (uri.getScheme().equals(PROTOCOL_HTTP)) { WebResource resource = new WebResource(uri, proxyHost, proxyPort); int size = resource.getSize(); resource.shutdown(); return size; } return uri.toURL().openConnection().getContentLength(); } catch (IOException e) { return 0; } }
try { if (uri.getScheme().equals(PROTOCOL_HTTP)) { WebResource resource = new WebResource(uri, proxyHost, proxyPort); long time = resource.getLastModified(); resource.shutdown(); return time;
/** * Copy this WebResource to the destination. * * @param dest the destination URI * @throws LucidException when an error is encountered */ public void copy(URI dest) throws LucidException { copy(dest, null); }
int size = getHeaderAsInt(response, "Content-Length"); size = getSize();
/** * Determine the last modified date of this WebResource. * <p> * Note that the http client may read the entire file. * </p> * * @return the last mod date of the file */ public long getLastModified() { HttpRequestBase method = new HttpHead(uri); HttpResponse response = null; try { // Execute the method. response = client.execute(method); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { return getHeaderAsDate(response, "Last-Modified"); } String reason = response.getStatusLine().getReasonPhrase(); // TRANSLATOR: Common error condition: {0} is a placeholder for the // URL of what could not be found. Reporter.informUser(this, JSMsg.gettext("Unable to find: {0}", reason + ':' + uri.getPath())); } catch (IOException e) { return new Date().getTime(); } return new Date().getTime(); }
/** * Determine the size of this WebResource. * <p> * Note that the http client may read the entire file to determine this. * </p> * * @return the size of the file */ public int getSize() { HttpRequestBase method = new HttpHead(uri); HttpResponse response = null; try { // Execute the method. response = client.execute(method); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { return getHeaderAsInt(response, "Content-Length"); } String reason = response.getStatusLine().getReasonPhrase(); // TRANSLATOR: Common error condition: {0} is a placeholder for the // URL of what could not be found. Reporter.informUser(this, JSMsg.gettext("Unable to find: {0}", reason + ':' + uri.getPath())); } catch (IOException e) { return 0; } return 0; }
WebResource.setTimeout(20000);
private void copy(Progress job, URI source, URI dest) throws InstallException { Log.d(TAG, "Downloading "+source+" to "+dest); if (job != null) { // TRANSLATOR: Progress label for downloading one or more files. job.setSectionName(JSMsg.gettext("Downloading files")); } // last 2 params are proxies which I hope we can ignore on Android WebResource wr = new WebResource(source, null, null); try { wr.copy(dest, job); } catch (LucidException le) { // TRANSLATOR: Common error condition: {0} is a placeholder for the URL of what could not be found. throw new InstallException(JSMsg.gettext("Unable to find: {0}", source.toString()), le); } finally { wr.shutdown(); } } }