Package org.apache.ivy.util.url
Class URLHandlerDispatcher
java.lang.Object
org.apache.ivy.util.url.URLHandlerDispatcher
- All Implemented Interfaces:
TimeoutConstrainedURLHandler
,URLHandler
An implementation of
URLHandler
which uses an underlying URLHandler
per protocol
and a fallback default URLHandler
for dealing with downloads, uploads and
general reachability checks-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.ivy.util.url.URLHandler
URLHandler.URLInfo
-
Field Summary
Fields inherited from interface org.apache.ivy.util.url.URLHandler
REQUEST_METHOD_GET, REQUEST_METHOD_HEAD, UNAVAILABLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
download
(URL src, File dest, CopyProgressListener l) void
download
(URL src, File dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) Downloads the resource available atsrc
to the targetdest
long
getContentLength
(URL url) Please prefer getURLInfo when several infos are needed.long
getContentLength
(URL url, int timeout) long
getContentLength
(URL url, TimeoutConstraint timeoutConstraint) Returns the number of bytes of data that's available for the resource at the passedurl
.getHandler
(String protocol) long
getLastModified
(URL url) Please prefer getURLInfo when several infos are needed.long
getLastModified
(URL url, int timeout) Please prefer getURLInfo when several infos are needed.long
getLastModified
(URL url, TimeoutConstraint timeoutConstraint) Returns the last modified timestamp of the resource accessible at the passedurl
.getURLInfo
(URL url) getURLInfo
(URL url, int timeout) getURLInfo
(URL url, TimeoutConstraint timeoutConstraint) Returns theURLHandler.URLInfo
extracted from the given url, orURLHandler.UNAVAILABLE
when the url is not reachable.boolean
isReachable
(URL url) Please prefer getURLInfo when several infos are needed.boolean
isReachable
(URL url, int timeout) Please prefer getURLInfo when several infos are needed.boolean
isReachable
(URL url, TimeoutConstraint timeoutConstraint) Returns true if the passedURL
is reachable.openStream
(URL url) openStream
(URL url, TimeoutConstraint timeoutConstraint) Opens and returns anInputStream
to the passedurl
.void
setDefault
(URLHandler default1) void
setDownloader
(String protocol, URLHandler downloader) void
setRequestMethod
(int requestMethod) void
upload
(File src, URL dest, CopyProgressListener l) void
upload
(File src, URL dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint)
-
Constructor Details
-
URLHandlerDispatcher
public URLHandlerDispatcher()
-
-
Method Details
-
isReachable
Description copied from interface:URLHandler
Please prefer getURLInfo when several infos are needed.- Specified by:
isReachable
in interfaceURLHandler
- Parameters:
url
- the url to check- Returns:
- true if the target is reachable
-
isReachable
Description copied from interface:URLHandler
Please prefer getURLInfo when several infos are needed.- Specified by:
isReachable
in interfaceURLHandler
- Parameters:
url
- the url to checktimeout
- the timeout in milliseconds- Returns:
- true if the target is reachable
-
isReachable
Description copied from interface:TimeoutConstrainedURLHandler
Returns true if the passedURL
is reachable. Else returns false. Uses the passedtimeoutConstraint
for determining the connectivity to the URL.Please use
TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint)
if more one information about theurl
is needed- Specified by:
isReachable
in interfaceTimeoutConstrainedURLHandler
- Parameters:
url
- The URL to accesstimeoutConstraint
- The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific- Returns:
- boolean
-
getContentLength
Description copied from interface:URLHandler
Please prefer getURLInfo when several infos are needed.- Specified by:
getContentLength
in interfaceURLHandler
- Parameters:
url
- the url to check- Returns:
- the length of the target if the given url is reachable, 0 otherwise. No error code in case of http urls.
-
getContentLength
- Specified by:
getContentLength
in interfaceURLHandler
- Parameters:
url
- the url to checktimeout
- the maximum time before considering an url is not reachable a timeout of zero indicates no timeout- Returns:
- the length of the target if the given url is reachable, 0 otherwise. No error code in case of http urls.
-
getContentLength
Description copied from interface:TimeoutConstrainedURLHandler
Returns the number of bytes of data that's available for the resource at the passedurl
. Returns 0 if the passedurl
isn't reachable- Specified by:
getContentLength
in interfaceTimeoutConstrainedURLHandler
- Parameters:
url
- The URL to accesstimeoutConstraint
- The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific- Returns:
- long
-
getLastModified
Description copied from interface:URLHandler
Please prefer getURLInfo when several infos are needed.- Specified by:
getLastModified
in interfaceURLHandler
- Parameters:
url
- the url to check- Returns:
- last modified timestamp of the given url
-
getLastModified
Description copied from interface:URLHandler
Please prefer getURLInfo when several infos are needed.- Specified by:
getLastModified
in interfaceURLHandler
- Parameters:
url
- the url to checktimeout
- the timeout in milliseconds- Returns:
- last modified timestamp of the given url
-
getLastModified
Description copied from interface:TimeoutConstrainedURLHandler
Returns the last modified timestamp of the resource accessible at the passedurl
.Please use
TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint)
if more one information about theurl
is needed- Specified by:
getLastModified
in interfaceTimeoutConstrainedURLHandler
- Parameters:
url
- The URL to accesstimeoutConstraint
- The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific- Returns:
- long
-
getURLInfo
- Specified by:
getURLInfo
in interfaceURLHandler
- Parameters:
url
- The url from which information is retrieved.- Returns:
- The URLInfo extracted from the given url, or
URLHandler.UNAVAILABLE
instance when the url is not reachable.
-
getURLInfo
- Specified by:
getURLInfo
in interfaceURLHandler
- Parameters:
url
- The url from which information is retrieved.timeout
- The timeout in milliseconds.- Returns:
- The URLInfo extracted from the given url, or
URLHandler.UNAVAILABLE
when the url is not reachable, never null.
-
getURLInfo
Description copied from interface:TimeoutConstrainedURLHandler
Returns theURLHandler.URLInfo
extracted from the given url, orURLHandler.UNAVAILABLE
when the url is not reachable. Never returns null.- Specified by:
getURLInfo
in interfaceTimeoutConstrainedURLHandler
- Parameters:
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 specific- Returns:
- URLInfo
-
openStream
- Specified by:
openStream
in interfaceURLHandler
- Parameters:
url
- ditto- Returns:
- InputStream
- Throws:
IOException
- if something goes wrong
-
openStream
Description copied from interface:TimeoutConstrainedURLHandler
Opens and returns anInputStream
to the passedurl
.- Specified by:
openStream
in interfaceTimeoutConstrainedURLHandler
- Parameters:
url
- The URL to which anInputStream
has to be openedtimeoutConstraint
- The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific- Returns:
- InputStream
- Throws:
IOException
- if something goes wrong
-
download
- Specified by:
download
in interfaceURLHandler
- Parameters:
src
- URLdest
- Filel
- CopyProgressListener- Throws:
IOException
- if something goes wrong
-
download
public void download(URL src, File dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws IOException Description copied from interface:TimeoutConstrainedURLHandler
Downloads the resource available atsrc
to the targetdest
- Specified by:
download
in interfaceTimeoutConstrainedURLHandler
- Parameters:
src
- The source URL to download the resource fromdest
- The destinationFile
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 specific- Throws:
IOException
- if something goes wrong
-
upload
- Specified by:
upload
in interfaceURLHandler
- Parameters:
src
- Filedest
- URLl
- CopyProgressListener- Throws:
IOException
- if something goes wrong
-
upload
public void upload(File src, URL dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws IOException Description copied from interface:TimeoutConstrainedURLHandler
- Specified by:
upload
in interfaceTimeoutConstrainedURLHandler
- Parameters:
src
- The sourceFile
to uploaddest
- The target URL where theFile
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 specific- Throws:
IOException
- if something goes wrong
-
setRequestMethod
public void setRequestMethod(int requestMethod) - Specified by:
setRequestMethod
in interfaceURLHandler
-
setDownloader
-
getHandler
-
getDefault
-
setDefault
-