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.URLInfo
REQUEST_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)
URLHandler
isReachable
in interface URLHandler
url
- the url to checkpublic boolean isReachable(java.net.URL url, int timeout)
URLHandler
isReachable
in interface URLHandler
url
- the url to checktimeout
- the timeout in millisecondspublic boolean isReachable(java.net.URL url, TimeoutConstraint timeoutConstraint)
TimeoutConstrainedURLHandler
URL
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 TimeoutConstrainedURLHandler
url
- 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)
URLHandler
getContentLength
in interface URLHandler
url
- the url to checkpublic long getContentLength(java.net.URL url, int timeout)
getContentLength
in interface URLHandler
url
- 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)
TimeoutConstrainedURLHandler
url
. Returns 0 if the passed url
isn't reachablegetContentLength
in interface TimeoutConstrainedURLHandler
url
- 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)
URLHandler
getLastModified
in interface URLHandler
url
- the url to checkpublic long getLastModified(java.net.URL url, int timeout)
URLHandler
getLastModified
in interface URLHandler
url
- the url to checktimeout
- the timeout in millisecondspublic long getLastModified(java.net.URL url, TimeoutConstraint timeoutConstraint)
TimeoutConstrainedURLHandler
url
.
Please use TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint)
if more one information about the
url
is needed
getLastModified
in interface TimeoutConstrainedURLHandler
url
- 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 URLHandler
url
- 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 URLHandler
url
- 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)
TimeoutConstrainedURLHandler
URLInfo
extracted from the given url, or URLHandler.UNAVAILABLE
when the
url is not reachable. Never returns null.getURLInfo
in interface TimeoutConstrainedURLHandler
url
- 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 URLHandler
url
- dittojava.io.IOException
- if something goes wrongpublic java.io.InputStream openStream(java.net.URL url, TimeoutConstraint timeoutConstraint) throws java.io.IOException
TimeoutConstrainedURLHandler
InputStream
to the passed url
.openStream
in interface TimeoutConstrainedURLHandler
url
- 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 URLHandler
src
- 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
TimeoutConstrainedURLHandler
src
to the target dest
download
in interface TimeoutConstrainedURLHandler
src
- 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 URLHandler
src
- 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
TimeoutConstrainedURLHandler
src
File
to the target dest
URL
upload
in interface TimeoutConstrainedURLHandler
src
- 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 URLHandler
public 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-2020 The Apache Software Foundation, Licensed under Apache License, Version 2.0.