public class BasicURLHandler extends AbstractURLHandler implements TimeoutConstrainedURLHandler
URLHandler.URLInfo
REQUEST_METHOD_GET, REQUEST_METHOD_HEAD, UNAVAILABLE
Constructor and Description |
---|
BasicURLHandler() |
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 |
static java.lang.String |
getCharSetFromContentType(java.lang.String contentType)
Extract the charset from the Content-Type header string, or default to ISO-8859-1 as per
rfc2616-sec3.html#sec3.7.1 .
|
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 . |
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,
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 |
upload(java.io.File source,
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 |
createTimeoutConstraints, getContentLength, getContentLength, getDecodingInputStream, getLastModified, getLastModified, getRequestMethod, getUserAgent, isReachable, isReachable, normalizeToString, normalizeToURL, setRequestMethod, validatePutStatusCode
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getContentLength, getContentLength, getLastModified, getLastModified, isReachable, isReachable, setRequestMethod
public 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 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, 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, 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, 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 static java.lang.String getCharSetFromContentType(java.lang.String contentType)
contentType
- the Content-Type header stringpublic 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 source, java.net.URL dest, CopyProgressListener l) throws java.io.IOException
upload
in interface URLHandler
source
- 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 wrongCopyright ©2007-2020 The Apache Software Foundation, Licensed under Apache License, Version 2.0.