Class URLHandlerDispatcher

java.lang.Object
org.apache.ivy.util.url.URLHandlerDispatcher
All Implemented Interfaces:
TimeoutConstrainedURLHandler, URLHandler

public class URLHandlerDispatcher extends Object implements TimeoutConstrainedURLHandler
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
  • Constructor Details

    • URLHandlerDispatcher

      public URLHandlerDispatcher()
  • Method Details

    • isReachable

      public boolean isReachable(URL url)
      Description copied from interface: URLHandler
      Please prefer getURLInfo when several infos are needed.
      Specified by:
      isReachable in interface URLHandler
      Parameters:
      url - the url to check
      Returns:
      true if the target is reachable
    • isReachable

      public boolean isReachable(URL url, int timeout)
      Description copied from interface: URLHandler
      Please prefer getURLInfo when several infos are needed.
      Specified by:
      isReachable in interface URLHandler
      Parameters:
      url - the url to check
      timeout - the timeout in milliseconds
      Returns:
      true if the target is reachable
    • isReachable

      public boolean isReachable(URL url, TimeoutConstraint timeoutConstraint)
      Description copied from interface: TimeoutConstrainedURLHandler
      Returns true if the passed 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

      Specified by:
      isReachable in interface TimeoutConstrainedURLHandler
      Parameters:
      url - The URL to access
      timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
      Returns:
      boolean
    • getContentLength

      public long getContentLength(URL url)
      Description copied from interface: URLHandler
      Please prefer getURLInfo when several infos are needed.
      Specified by:
      getContentLength in interface URLHandler
      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(URL url, int timeout)
      Specified by:
      getContentLength in interface URLHandler
      Parameters:
      url - the url to check
      timeout - 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(URL url, TimeoutConstraint timeoutConstraint)
      Description copied from interface: TimeoutConstrainedURLHandler
      Returns the number of bytes of data that's available for the resource at the passed url. Returns 0 if the passed url isn't reachable
      Specified by:
      getContentLength in interface TimeoutConstrainedURLHandler
      Parameters:
      url - The URL to access
      timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
      Returns:
      long
    • getLastModified

      public long getLastModified(URL url)
      Description copied from interface: URLHandler
      Please prefer getURLInfo when several infos are needed.
      Specified by:
      getLastModified in interface URLHandler
      Parameters:
      url - the url to check
      Returns:
      last modified timestamp of the given url
    • getLastModified

      public long getLastModified(URL url, int timeout)
      Description copied from interface: URLHandler
      Please prefer getURLInfo when several infos are needed.
      Specified by:
      getLastModified in interface URLHandler
      Parameters:
      url - the url to check
      timeout - the timeout in milliseconds
      Returns:
      last modified timestamp of the given url
    • getLastModified

      public long getLastModified(URL url, TimeoutConstraint timeoutConstraint)
      Description copied from interface: TimeoutConstrainedURLHandler
      Returns the last modified timestamp of the resource accessible at the passed url.

      Please use TimeoutConstrainedURLHandler.getURLInfo(URL, TimeoutConstraint) if more one information about the url is needed

      Specified by:
      getLastModified in interface TimeoutConstrainedURLHandler
      Parameters:
      url - The URL to access
      timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
      Returns:
      long
    • getURLInfo

      public URLHandler.URLInfo getURLInfo(URL url)
      Specified by:
      getURLInfo in interface URLHandler
      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

      public URLHandler.URLInfo getURLInfo(URL url, int timeout)
      Specified by:
      getURLInfo in interface URLHandler
      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

      public URLHandler.URLInfo getURLInfo(URL url, TimeoutConstraint timeoutConstraint)
      Description copied from interface: TimeoutConstrainedURLHandler
      Returns the URLHandler.URLInfo extracted from the given url, or URLHandler.UNAVAILABLE when the url is not reachable. Never returns null.
      Specified by:
      getURLInfo in interface TimeoutConstrainedURLHandler
      Parameters:
      url - The URL for which the information is to be retrieved
      timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
      Returns:
      URLInfo
    • openStream

      public InputStream openStream(URL url) throws IOException
      Specified by:
      openStream in interface URLHandler
      Parameters:
      url - ditto
      Returns:
      InputStream
      Throws:
      IOException - if something goes wrong
    • openStream

      public InputStream openStream(URL url, TimeoutConstraint timeoutConstraint) throws IOException
      Description copied from interface: TimeoutConstrainedURLHandler
      Opens and returns an InputStream to the passed url.
      Specified by:
      openStream in interface TimeoutConstrainedURLHandler
      Parameters:
      url - The URL to which an InputStream has to be opened
      timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
      Returns:
      InputStream
      Throws:
      IOException - if something goes wrong
    • download

      public void download(URL src, File dest, CopyProgressListener l) throws IOException
      Specified by:
      download in interface URLHandler
      Parameters:
      src - URL
      dest - File
      l - 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 at src to the target dest
      Specified by:
      download in interface TimeoutConstrainedURLHandler
      Parameters:
      src - The source URL to download the resource from
      dest - The destination File to download the resource to
      listener - The listener that will be notified of the download progress
      timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
      Throws:
      IOException - if something goes wrong
    • upload

      public void upload(File src, URL dest, CopyProgressListener l) throws IOException
      Specified by:
      upload in interface URLHandler
      Parameters:
      src - File
      dest - URL
      l - 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
      Uploads the src File to the target dest URL
      Specified by:
      upload in interface TimeoutConstrainedURLHandler
      Parameters:
      src - The source File to upload
      dest - The target URL where the File has to be uploaded
      listener - The listener that will be notified of the upload progress
      timeoutConstraint - 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 interface URLHandler
    • setDownloader

      public void setDownloader(String protocol, URLHandler downloader)
    • getHandler

      public URLHandler getHandler(String protocol)
    • getDefault

      public URLHandler getDefault()
    • setDefault

      public void setDefault(URLHandler default1)