Package org.apache.ivy.util.url
Class URLHandlerDispatcher
- java.lang.Object
-
- org.apache.ivy.util.url.URLHandlerDispatcher
-
- All Implemented Interfaces:
TimeoutConstrainedURLHandler,URLHandler
public class URLHandlerDispatcher extends java.lang.Object implements TimeoutConstrainedURLHandler
An implementation ofURLHandlerwhich uses an underlyingURLHandlerper protocol and a fallback defaultURLHandlerfor 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 Constructor Description URLHandlerDispatcher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddownload(java.net.URL src, java.io.File dest, CopyProgressListener l)voiddownload(java.net.URL src, java.io.File dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint)Downloads the resource available atsrcto the targetdestlonggetContentLength(java.net.URL url)Please prefer getURLInfo when several infos are needed.longgetContentLength(java.net.URL url, int timeout)longgetContentLength(java.net.URL url, TimeoutConstraint timeoutConstraint)Returns the number of bytes of data that's available for the resource at the passedurl.URLHandlergetDefault()URLHandlergetHandler(java.lang.String protocol)longgetLastModified(java.net.URL url)Please prefer getURLInfo when several infos are needed.longgetLastModified(java.net.URL url, int timeout)Please prefer getURLInfo when several infos are needed.longgetLastModified(java.net.URL url, TimeoutConstraint timeoutConstraint)Returns the last modified timestamp of the resource accessible at the passedurl.URLHandler.URLInfogetURLInfo(java.net.URL url)URLHandler.URLInfogetURLInfo(java.net.URL url, int timeout)URLHandler.URLInfogetURLInfo(java.net.URL url, TimeoutConstraint timeoutConstraint)Returns theURLHandler.URLInfoextracted from the given url, orURLHandler.UNAVAILABLEwhen the url is not reachable.booleanisReachable(java.net.URL url)Please prefer getURLInfo when several infos are needed.booleanisReachable(java.net.URL url, int timeout)Please prefer getURLInfo when several infos are needed.booleanisReachable(java.net.URL url, TimeoutConstraint timeoutConstraint)Returns true if the passedURLis reachable.java.io.InputStreamopenStream(java.net.URL url)java.io.InputStreamopenStream(java.net.URL url, TimeoutConstraint timeoutConstraint)Opens and returns anInputStreamto the passedurl.voidsetDefault(URLHandler default1)voidsetDownloader(java.lang.String protocol, URLHandler downloader)voidsetRequestMethod(int requestMethod)voidupload(java.io.File src, java.net.URL dest, CopyProgressListener l)voidupload(java.io.File src, java.net.URL dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint)Uploads thesrcFileto the targetdestURL
-
-
-
Method Detail
-
isReachable
public boolean isReachable(java.net.URL url)
Description copied from interface:URLHandlerPlease prefer getURLInfo when several infos are needed.- Specified by:
isReachablein interfaceURLHandler- Parameters:
url- the url to check- Returns:
- true if the target is reachable
-
isReachable
public boolean isReachable(java.net.URL url, int timeout)Description copied from interface:URLHandlerPlease prefer getURLInfo when several infos are needed.- Specified by:
isReachablein interfaceURLHandler- Parameters:
url- the url to checktimeout- the timeout in milliseconds- Returns:
- true if the target is reachable
-
isReachable
public boolean isReachable(java.net.URL url, TimeoutConstraint timeoutConstraint)Description copied from interface:TimeoutConstrainedURLHandlerReturns true if the passedURLis reachable. Else returns false. Uses the passedtimeoutConstraintfor determining the connectivity to the URL.Please use
TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint)if more one information about theurlis needed- Specified by:
isReachablein 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
public long getContentLength(java.net.URL url)
Description copied from interface:URLHandlerPlease prefer getURLInfo when several infos are needed.- Specified by:
getContentLengthin 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
public long getContentLength(java.net.URL url, int timeout)- Specified by:
getContentLengthin 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
public long getContentLength(java.net.URL url, TimeoutConstraint timeoutConstraint)Description copied from interface:TimeoutConstrainedURLHandlerReturns the number of bytes of data that's available for the resource at the passedurl. Returns 0 if the passedurlisn't reachable- Specified by:
getContentLengthin 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
public long getLastModified(java.net.URL url)
Description copied from interface:URLHandlerPlease prefer getURLInfo when several infos are needed.- Specified by:
getLastModifiedin interfaceURLHandler- Parameters:
url- the url to check- Returns:
- last modified timestamp of the given url
-
getLastModified
public long getLastModified(java.net.URL url, int timeout)Description copied from interface:URLHandlerPlease prefer getURLInfo when several infos are needed.- Specified by:
getLastModifiedin interfaceURLHandler- Parameters:
url- the url to checktimeout- the timeout in milliseconds- Returns:
- last modified timestamp of the given url
-
getLastModified
public long getLastModified(java.net.URL url, TimeoutConstraint timeoutConstraint)Description copied from interface:TimeoutConstrainedURLHandlerReturns the last modified timestamp of the resource accessible at the passedurl.Please use
TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint)if more one information about theurlis needed- Specified by:
getLastModifiedin 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
public URLHandler.URLInfo getURLInfo(java.net.URL url)
- Specified by:
getURLInfoin interfaceURLHandler- Parameters:
url- The url from which information is retrieved.- Returns:
- The URLInfo extracted from the given url, or
URLHandler.UNAVAILABLEinstance when the url is not reachable.
-
getURLInfo
public URLHandler.URLInfo getURLInfo(java.net.URL url, int timeout)
- Specified by:
getURLInfoin 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.UNAVAILABLEwhen the url is not reachable, never null.
-
getURLInfo
public URLHandler.URLInfo getURLInfo(java.net.URL url, TimeoutConstraint timeoutConstraint)
Description copied from interface:TimeoutConstrainedURLHandlerReturns theURLHandler.URLInfoextracted from the given url, orURLHandler.UNAVAILABLEwhen the url is not reachable. Never returns null.- Specified by:
getURLInfoin 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
public java.io.InputStream openStream(java.net.URL url) throws java.io.IOException- Specified by:
openStreamin interfaceURLHandler- Parameters:
url- ditto- Returns:
- InputStream
- Throws:
java.io.IOException- if something goes wrong
-
openStream
public java.io.InputStream openStream(java.net.URL url, TimeoutConstraint timeoutConstraint) throws java.io.IOExceptionDescription copied from interface:TimeoutConstrainedURLHandlerOpens and returns anInputStreamto the passedurl.- Specified by:
openStreamin interfaceTimeoutConstrainedURLHandler- Parameters:
url- The URL to which anInputStreamhas to be openedtimeoutConstraint- The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific- Returns:
- InputStream
- Throws:
java.io.IOException- if something goes wrong
-
download
public void download(java.net.URL src, java.io.File dest, CopyProgressListener l) throws java.io.IOException- Specified by:
downloadin interfaceURLHandler- Parameters:
src- URLdest- Filel- CopyProgressListener- Throws:
java.io.IOException- if something goes wrong
-
download
public void download(java.net.URL src, java.io.File dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws java.io.IOExceptionDescription copied from interface:TimeoutConstrainedURLHandlerDownloads the resource available atsrcto the targetdest- Specified by:
downloadin interfaceTimeoutConstrainedURLHandler- Parameters:
src- The source URL to download the resource fromdest- The destinationFileto 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:
java.io.IOException- if something goes wrong
-
upload
public void upload(java.io.File src, java.net.URL dest, CopyProgressListener l) throws java.io.IOException- Specified by:
uploadin interfaceURLHandler- Parameters:
src- Filedest- URLl- CopyProgressListener- Throws:
java.io.IOException- if something goes wrong
-
upload
public void upload(java.io.File src, java.net.URL dest, CopyProgressListener listener, TimeoutConstraint timeoutConstraint) throws java.io.IOExceptionDescription copied from interface:TimeoutConstrainedURLHandlerUploads thesrcFileto the targetdestURL- Specified by:
uploadin interfaceTimeoutConstrainedURLHandler- Parameters:
src- The sourceFileto uploaddest- The target URL where theFilehas 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:
java.io.IOException- if something goes wrong
-
setRequestMethod
public void setRequestMethod(int requestMethod)
- Specified by:
setRequestMethodin interfaceURLHandler
-
setDownloader
public void setDownloader(java.lang.String protocol, URLHandler downloader)
-
getHandler
public URLHandler getHandler(java.lang.String protocol)
-
getDefault
public URLHandler getDefault()
-
setDefault
public void setDefault(URLHandler default1)
-
-