org.apache.ivy.util.url

Interface URLHandler

public interface URLHandler

This interface is responsible for handling some URL manipulation (stream opening, downloading, check reachability, ...).
Nested Class Summary
static classURLHandler.URLInfo
Field Summary
static intREQUEST_METHOD_GET
Using the slower REQUEST method for getting the basic URL infos.
static intREQUEST_METHOD_HEAD
Using the faster HEAD method for getting the basic URL infos.
static URLHandler.URLInfoUNAVAILABLE
Method Summary
voiddownload(URL src, File dest, CopyProgressListener l)
longgetContentLength(URL url)
Returns the length of the target if the given url is reachable, and without error code in case of http urls.
longgetContentLength(URL url, int timeout)
Returns the length of the target if the given url is reachable, and without error code in case of http urls.
longgetLastModified(URL url)
Please prefer getURLInfo when several infos are needed.
longgetLastModified(URL url, int timeout)
Please prefer getURLInfo when several infos are needed.
URLHandler.URLInfogetURLInfo(URL url)
Returns the URLInfo of the given url or a UNAVAILABLE instance, if the url is not reachable.
URLHandler.URLInfogetURLInfo(URL url, int timeout)
never returns null, return UNAVAILABLE when url is not reachable
booleanisReachable(URL url)
Please prefer getURLInfo when several infos are needed.
booleanisReachable(URL url, int timeout)
Please prefer getURLInfo when several infos are needed.
InputStreamopenStream(URL url)
voidsetRequestMethod(int requestMethod)
voidupload(File src, URL dest, CopyProgressListener l)

Field Detail

REQUEST_METHOD_GET

public static final int REQUEST_METHOD_GET
Using the slower REQUEST method for getting the basic URL infos. Use this when getting errors behind a problematic/special proxy or firewall chain.

REQUEST_METHOD_HEAD

public static final int REQUEST_METHOD_HEAD
Using the faster HEAD method for getting the basic URL infos. Works for most common networks.

UNAVAILABLE

public static final URLHandler.URLInfo UNAVAILABLE

Method Detail

download

public void download(URL src, File dest, CopyProgressListener l)

getContentLength

public long getContentLength(URL url)
Returns the length of the target if the given url is reachable, and without error code in case of http urls. Please prefer getURLInfo when several infos are needed.

Parameters: url the url to check

Returns: the length of the target if available, 0 if not reachable

getContentLength

public long getContentLength(URL url, int timeout)
Returns the length of the target if the given url is reachable, and without error code in case of http urls.

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 available, 0 if not reachable

getLastModified

public long getLastModified(URL url)
Please prefer getURLInfo when several infos are needed.

Parameters: url the url to check

Returns: last modified timestamp of the given url

getLastModified

public long getLastModified(URL url, int timeout)
Please prefer getURLInfo when several infos are needed.

Parameters: url the url to check

Returns: last modified timestamp of the given url

getURLInfo

public URLHandler.URLInfo getURLInfo(URL url)
Returns the URLInfo of the given url or a UNAVAILABLE instance, if the url is not reachable.

Parameters: url The url from which information is retrieved.

Returns: The URLInfo extracted from the given url, or UNAVAILABLE when the url is not available.

getURLInfo

public URLHandler.URLInfo getURLInfo(URL url, int timeout)
never returns null, return UNAVAILABLE when url is not reachable

Parameters: url The url from which information is retrieved. timeout The timeout in milliseconds.

Returns: The URLInfo extracted from the given url, or UNAVAILABLE when the url is not available.

isReachable

public boolean isReachable(URL url)
Please prefer getURLInfo when several infos are needed.

Parameters: url the url to check

Returns: true if the target is reachable

isReachable

public boolean isReachable(URL url, int timeout)
Please prefer getURLInfo when several infos are needed.

Parameters: url the url to check

Returns: true if the target is reachable

openStream

public InputStream openStream(URL url)

setRequestMethod

public void setRequestMethod(int requestMethod)

upload

public void upload(File src, URL dest, CopyProgressListener l)