public class WebResource extends Object
The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private org.apache.http.impl.client.CloseableHttpClient |
client |
private static int |
timeout
Define a 750 ms timeout to get a connection
|
private URI |
uri |
Constructor and Description |
---|
WebResource(URI theURI)
Construct a WebResource for the given URL, while timing out if too much
time has passed.
|
WebResource(URI theURI,
int theTimeout)
Construct a WebResource for the given URL, while timing out if too much
time has passed.
|
WebResource(URI theURI,
String theProxyHost)
Construct a WebResource for the given URL, going through the optional
proxy and default port, while timing out if too much time has passed.
|
WebResource(URI theURI,
String theProxyHost,
int theTimeout)
Construct a WebResource for the given URL, going through the optional
proxy and default port, while timing out if too much time has passed.
|
WebResource(URI theURI,
String theProxyHost,
Integer theProxyPort)
Construct a WebResource for the given URL, going through the optional
proxy and port, while timing out if too much time has passed.
|
WebResource(URI theURI,
String theProxyHost,
Integer theProxyPort,
int theTimeout)
Construct a WebResource for the given URL, going through the optional
proxy and port, while timing out if too much time has passed.
|
Modifier and Type | Method and Description |
---|---|
void |
copy(URI dest)
Copy this WebResource to the destination.
|
void |
copy(URI dest,
Progress meter)
Copy this WebResource to the destination and report progress.
|
private long |
getHeaderAsDate(org.apache.http.HttpResponse response,
String field)
Get the number of seconds since start of epoch for the field in the response headers as a Date.
|
private int |
getHeaderAsInt(org.apache.http.HttpResponse response,
String field)
Get the field as a long.
|
long |
getLastModified()
Determine the last modified date of this WebResource.
|
int |
getSize()
Determine the size of this WebResource.
|
static int |
getTimeout() |
static void |
setTimeout(int timeout) |
void |
shutdown()
When this WebResource is no longer needed it should be shutdown to return
underlying resources back to the OS.
|
private static int timeout
private URI uri
private org.apache.http.impl.client.CloseableHttpClient client
public WebResource(URI theURI)
theURI
- the Resource to get via HTTPpublic WebResource(URI theURI, int theTimeout)
theURI
- the Resource to get via HTTPtheTimeout
- the length of time in milliseconds to allow a connection to
respond before timing outpublic WebResource(URI theURI, String theProxyHost)
theURI
- the Resource to get via HTTPtheProxyHost
- the proxy host or nullpublic WebResource(URI theURI, String theProxyHost, int theTimeout)
theURI
- the Resource to get via HTTPtheProxyHost
- the proxy host or nulltheTimeout
- the length of time in milliseconds to allow a connection to
respond before timing outpublic WebResource(URI theURI, String theProxyHost, Integer theProxyPort)
theURI
- the Resource to get via HTTPtheProxyHost
- the proxy host or nulltheProxyPort
- the proxy port or null, where null means use the standard portpublic WebResource(URI theURI, String theProxyHost, Integer theProxyPort, int theTimeout)
theURI
- the Resource to get via HTTPtheProxyHost
- the proxy host or nulltheProxyPort
- the proxy port or null, where null means use the standard porttheTimeout
- the length of time in milliseconds to allow a connection to
respond before timing outpublic void shutdown()
public static int getTimeout()
public static void setTimeout(int timeout)
timeout
- the timeout to set in millisecondspublic int getSize()
Note that the http client may read the entire file to determine this.
public long getLastModified()
Note that the http client may read the entire file.
public void copy(URI dest, Progress meter) throws LucidException
dest
- the URI of the destination, typically a file:///.meter
- the job on which to report progressLucidException
- when an error is encounteredpublic void copy(URI dest) throws LucidException
dest
- the destination URILucidException
- when an error is encounteredprivate int getHeaderAsInt(org.apache.http.HttpResponse response, String field)
response
- The response from the requestfield
- the header field to checkprivate long getHeaderAsDate(org.apache.http.HttpResponse response, String field)
response
- The response from the requestfield
- the header field to check