Example usage for org.apache.commons.httpclient.util HttpURLConnection HttpURLConnection

List of usage examples for org.apache.commons.httpclient.util HttpURLConnection HttpURLConnection

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util HttpURLConnection HttpURLConnection.

Prototype

public HttpURLConnection(HttpMethod paramHttpMethod, URL paramURL) 

Source Link

Usage

From source file:org.crosswire.common.util.WebResource.java

/**
 * 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/*from  www  .ja v  a 2  s.  c o  m*/
 */
public int getSize() {
    HttpMethod method = new HeadMethod(uri.getPath());

    try {
        // Execute the method.
        int status = client.executeMethod(method);
        if (status == HttpStatus.SC_OK) {
            return new HttpURLConnection(method, NetUtil.toURL(uri)).getContentLength();
        }
        String reason = HttpStatus.getStatusText(status);
        Reporter.informUser(this, Msg.MISSING_FILE, new Object[] { reason + ':' + uri.getPath() });
    } catch (IOException e) {
        return 0;
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return 0;
}

From source file:org.crosswire.common.util.WebResource.java

/**
 * 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
 */// ww  w .  j av a2  s .c  o m
public long getLastModified() {
    HttpMethod method = new HeadMethod(uri.getPath());

    try {
        // Execute the method.
        if (client.executeMethod(method) == HttpStatus.SC_OK) {
            return new HttpURLConnection(method, NetUtil.toURL(uri)).getLastModified();
        }
    } catch (IOException e) {
        return new Date().getTime();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return new Date().getTime();
}