public class URLHandlerDispatcher extends java.lang.Object implements TimeoutConstrainedURLHandler
URLHandler which uses an underlying URLHandler per protocol
and a fallback default URLHandler for dealing with downloads, uploads and
general reachability checksURLHandler.URLInfoREQUEST_METHOD_GET, REQUEST_METHOD_HEAD, UNAVAILABLE| Constructor and Description |
|---|
URLHandlerDispatcher() |
| Modifier and Type | Method and Description |
|---|---|
void |
download(java.net.URL src,
java.io.File dest,
CopyProgressListener l) |
void |
download(java.net.URL src,
java.io.File dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint)
Downloads the resource available at
src to the target dest |
long |
getContentLength(java.net.URL url)
Please prefer getURLInfo when several infos are needed.
|
long |
getContentLength(java.net.URL url,
int timeout) |
long |
getContentLength(java.net.URL url,
TimeoutConstraint timeoutConstraint)
Returns the number of bytes of data that's available for the resource at the passed
url. |
URLHandler |
getDefault() |
URLHandler |
getHandler(java.lang.String protocol) |
long |
getLastModified(java.net.URL url)
Please prefer getURLInfo when several infos are needed.
|
long |
getLastModified(java.net.URL url,
int timeout)
Please prefer getURLInfo when several infos are needed.
|
long |
getLastModified(java.net.URL url,
TimeoutConstraint timeoutConstraint)
Returns the last modified timestamp of the resource accessible at the passed
url. |
URLHandler.URLInfo |
getURLInfo(java.net.URL url) |
URLHandler.URLInfo |
getURLInfo(java.net.URL url,
int timeout) |
URLHandler.URLInfo |
getURLInfo(java.net.URL url,
TimeoutConstraint timeoutConstraint)
Returns the
URLInfo extracted from the given url, or URLHandler.UNAVAILABLE when the
url is not reachable. |
boolean |
isReachable(java.net.URL url)
Please prefer getURLInfo when several infos are needed.
|
boolean |
isReachable(java.net.URL url,
int timeout)
Please prefer getURLInfo when several infos are needed.
|
boolean |
isReachable(java.net.URL url,
TimeoutConstraint timeoutConstraint)
Returns true if the passed
URL is reachable. |
java.io.InputStream |
openStream(java.net.URL url) |
java.io.InputStream |
openStream(java.net.URL url,
TimeoutConstraint timeoutConstraint)
Opens and returns an
InputStream to the passed url. |
void |
setDefault(URLHandler default1) |
void |
setDownloader(java.lang.String protocol,
URLHandler downloader) |
void |
setRequestMethod(int requestMethod) |
void |
upload(java.io.File src,
java.net.URL dest,
CopyProgressListener l) |
void |
upload(java.io.File src,
java.net.URL dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint)
Uploads the
src File to the target dest URL |
public boolean isReachable(java.net.URL url)
URLHandlerisReachable in interface URLHandlerurl - the url to checkpublic boolean isReachable(java.net.URL url,
int timeout)
URLHandlerisReachable in interface URLHandlerurl - the url to checktimeout - the timeout in millisecondspublic boolean isReachable(java.net.URL url,
TimeoutConstraint timeoutConstraint)
TimeoutConstrainedURLHandlerURL is reachable. Else returns false. Uses the
passed timeoutConstraint for determining the connectivity to the URL.
Please use TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint) if more one information about the
url is needed
isReachable in interface TimeoutConstrainedURLHandlerurl - The URL to accesstimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificpublic long getContentLength(java.net.URL url)
URLHandlergetContentLength in interface URLHandlerurl - the url to checkpublic long getContentLength(java.net.URL url,
int timeout)
getContentLength in interface URLHandlerurl - the url to checktimeout - the maximum time before considering an url is not reachable a
timeout of zero indicates no timeoutpublic long getContentLength(java.net.URL url,
TimeoutConstraint timeoutConstraint)
TimeoutConstrainedURLHandlerurl. Returns 0 if the passed url isn't reachablegetContentLength in interface TimeoutConstrainedURLHandlerurl - The URL to accesstimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificpublic long getLastModified(java.net.URL url)
URLHandlergetLastModified in interface URLHandlerurl - the url to checkpublic long getLastModified(java.net.URL url,
int timeout)
URLHandlergetLastModified in interface URLHandlerurl - the url to checktimeout - the timeout in millisecondspublic long getLastModified(java.net.URL url,
TimeoutConstraint timeoutConstraint)
TimeoutConstrainedURLHandlerurl.
Please use TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint) if more one information about the
url is needed
getLastModified in interface TimeoutConstrainedURLHandlerurl - The URL to accesstimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificpublic URLHandler.URLInfo getURLInfo(java.net.URL url)
getURLInfo in interface URLHandlerurl - The url from which information is retrieved.URLHandler.UNAVAILABLE instance when the
url is not reachable.public URLHandler.URLInfo getURLInfo(java.net.URL url, int timeout)
getURLInfo in interface URLHandlerurl - The url from which information is retrieved.timeout - The timeout in milliseconds.URLHandler.UNAVAILABLE when the url is
not reachable, never null.public URLHandler.URLInfo getURLInfo(java.net.URL url, TimeoutConstraint timeoutConstraint)
TimeoutConstrainedURLHandlerURLInfo extracted from the given url, or URLHandler.UNAVAILABLE when the
url is not reachable. Never returns null.getURLInfo in interface TimeoutConstrainedURLHandlerurl - The URL for which the information is to be retrievedtimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificpublic java.io.InputStream openStream(java.net.URL url)
throws java.io.IOException
openStream in interface URLHandlerurl - dittojava.io.IOException - if something goes wrongpublic java.io.InputStream openStream(java.net.URL url,
TimeoutConstraint timeoutConstraint)
throws java.io.IOException
TimeoutConstrainedURLHandlerInputStream to the passed url.openStream in interface TimeoutConstrainedURLHandlerurl - The URL to which an InputStream has to be openedtimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificjava.io.IOException - if something goes wrongpublic void download(java.net.URL src,
java.io.File dest,
CopyProgressListener l)
throws java.io.IOException
download in interface URLHandlersrc - URLdest - Filel - CopyProgressListenerjava.io.IOException - if something goes wrongpublic void download(java.net.URL src,
java.io.File dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint)
throws java.io.IOException
TimeoutConstrainedURLHandlersrc to the target destdownload in interface TimeoutConstrainedURLHandlersrc - The source URL to download the resource fromdest - The destination File to download the resource tolistener - The listener that will be notified of the download progresstimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificjava.io.IOException - if something goes wrongpublic void upload(java.io.File src,
java.net.URL dest,
CopyProgressListener l)
throws java.io.IOException
upload in interface URLHandlersrc - Filedest - URLl - CopyProgressListenerjava.io.IOException - if something goes wrongpublic void upload(java.io.File src,
java.net.URL dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint)
throws java.io.IOException
TimeoutConstrainedURLHandlersrc File to the target dest URLupload in interface TimeoutConstrainedURLHandlersrc - The source File to uploaddest - The target URL where the File has to be uploadedlistener - The listener that will be notified of the upload progresstimeoutConstraint - The connectivity timeout constraints. Can be null, in which case
the timeouts are implementation specificjava.io.IOException - if something goes wrongpublic void setRequestMethod(int requestMethod)
setRequestMethod in interface URLHandlerpublic void setDownloader(java.lang.String protocol,
URLHandler downloader)
public URLHandler getHandler(java.lang.String protocol)
public URLHandler getDefault()
public void setDefault(URLHandler default1)
Copyright ©2007-2024 The Apache Software Foundation, Licensed under Apache License, Version 2.0.