|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.univocity.api.io.ReaderProvider
com.univocity.api.net.UrlReaderProvider
public class UrlReaderProvider
A ReaderProvider for URLs (parameterized or not).
This provider works with an internal HttpRequest configuration object
that allows you to configure a HTTP request. The actual remote invocation is performed when getResponse()
is called, and the result will be provided in a HttpResponse object.
Example of a URL with 2 parameters (QUERY and PERIOD): "https://www.google.com/?q={QUERY}#q={QUERY}&tbs=qdr:{PERIOD}"
Use HttpRequest.setUrlParameter(String, Object) to set the values of any parameters so that getUrl()
generates the final URL.
In case of failure receiving a response, the call can be retried for a number of times using setRetries(int)
and each retry can occur after a given interval, which can be defined with setRetryInterval(long)
The response body of a call can be stored in a local file defined using the storeLocalCopyIn(File) method.
| Constructor Summary | |
|---|---|
UrlReaderProvider(String url)
Creates a new instance to read content from a given URL. |
|
UrlReaderProvider(String url,
RateLimiter rateLimiter)
Creates a new instance to read content from a given URL. |
|
| Method Summary | |
|---|---|
UrlReaderProvider |
clone()
Clones this object with all its configuration, but without the result of the HTTP request (i.e. |
boolean |
equals(Object o)
|
String |
getDomainName()
Returns the domain name in the current URL. |
String |
getFileName()
Returns the file name specified in URL, if it exists. |
FileProvider |
getLocalCopyTarget()
Returns a FileProvider which indicates where in the filesystem a file with a copy of the response body,
obtained after invoking the HTTP request via the getResponse() method, should be stored. |
String |
getPath()
Gets the path of the resource identified by the URL. |
String |
getProtocol()
Returns the protocol of the current URL. |
HttpRequest |
getRequest()
Returns a HttpRequest object with configuration options for executing the HTTP request. |
Reader |
getResource()
Returns a Reader instance ready to process the content of the body of the HTTP response obtained
after invoking getResponse(). |
HttpResponse |
getResponse()
Invokes the HTTP request and returns the response as a HttpResponse object. |
int |
getRetries()
Return the number of retries to be performed in case the HTTP request call fails. |
long |
getRetryInterval()
Returns the interval (in milliseconds) to wait before trying to execute the HTTP request after a failure. |
String |
getUrl()
Returns the URL used to produce the current response. |
URL |
getUrlInstance()
Returns a URL instance used to produce the current response. |
int |
hashCode()
|
boolean |
isResponseAvailable()
Returns a flag indicating whether the HTTP request has been executed and a response is already available through getResponse(). |
UrlReaderProvider |
newRequest(String newUrl)
Clones this object with all its configuration and a new URL, but without the result of the HTTP request (i.e. |
void |
setRetries(int retries)
Defines a number of retries to be performed in case the HTTP request call fails. |
void |
setRetryInterval(long retryInterval)
Defines the interval (in milliseconds) to wait before trying to execute the HTTP request after a failure. |
void |
storeLocalCopyIn(File file)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored. |
void |
storeLocalCopyIn(File file,
Charset encoding)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored. |
void |
storeLocalCopyIn(FileProvider provider)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored be stored. |
void |
storeLocalCopyIn(File file,
String encoding)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored. |
void |
storeLocalCopyIn(String path)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored. |
void |
storeLocalCopyIn(String path,
Charset encoding)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored. |
void |
storeLocalCopyIn(String path,
String encoding)
Defines a file into which a copy of the response body, obtained after invoking the HTTP request via the getResponse() method, should be stored |
String |
toString()
Prints this object as the original HTTP request URL. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public UrlReaderProvider(String url)
url - the URL to access.
public UrlReaderProvider(String url,
RateLimiter rateLimiter)
url - the URL to access.rateLimiter - RateLimiter that ensures multiple requests execute one after the other, after a minimum interval.| Method Detail |
|---|
public final String getUrl()
getResponse() was not invoked yet, the URL
provided in the constructor of this class will be returned. If redirection was enabled
(through HttpRequest.getFollowRedirects()), the redirection URL will be returned.
public final URL getUrlInstance()
URL instance used to produce the current response. If getResponse() was not invoked yet, the URL
provided in the constructor of this class will be returned. If redirection was enabled
(through HttpRequest.getFollowRedirects()), the redirection URL will be returned.
public final boolean isResponseAvailable()
getResponse().
true if a HttpResponse is available, otherwise falsepublic final String getDomainName()
getResponse()) with
redirection enabled, the domain name in the redirection URL will be returned.
public final HttpRequest getRequest()
HttpRequest object with configuration options for executing the HTTP request.
public final String getProtocol()
getResponse()) with
redirection enabled, the protocol of the redirection URL will be returned.
public final int getRetries()
public final void setRetries(int retries)
retries - the number of retries to perform in case of failure to obtain a responsepublic final long getRetryInterval()
public final void setRetryInterval(long retryInterval)
retryInterval - the retry interval in mspublic final String getPath()
public final String getFileName()
public final HttpResponse getResponse()
HttpResponse object.
Further calls to this method will produce the same object, and no further HTTP requests will be performed.
Use the clone() method to obtain a copy of the current UrlReaderProvider instance if you need
to invoke the HTTP request again.
public final void storeLocalCopyIn(FileProvider provider)
getResponse() method, should be stored be stored.
provider - the FileProvider defining the target file.public final void storeLocalCopyIn(File file)
getResponse() method, should be stored.
file - the target file.
public final void storeLocalCopyIn(File file,
Charset encoding)
getResponse() method, should be stored.
file - the target file.encoding - the encoding to use for the local copy.
public final void storeLocalCopyIn(File file,
String encoding)
getResponse() method, should be stored.
file - the target file.encoding - the encoding to use for the local copy.public final void storeLocalCopyIn(String path)
getResponse() method, should be stored.
path - a path to the target file. The path can contain system variables enclosed within
{ and } (e.g. {user.home}/myapp/page.html").
public final void storeLocalCopyIn(String path,
Charset encoding)
getResponse() method, should be stored.
path - a path to the target file. The path can contain system variables enclosed within
{ and } (e.g. {user.home}/myapp/page.html").encoding - the encoding to use for the local copy.
public final void storeLocalCopyIn(String path,
String encoding)
getResponse() method, should be stored
path - a path to the target file. The path can contain system variables enclosed within
{ and } (e.g. {user.home}/myapp/page.html").encoding - the encoding to use for the local copy.public final FileProvider getLocalCopyTarget()
FileProvider which indicates where in the filesystem a file with a copy of the response body,
obtained after invoking the HTTP request via the getResponse() method, should be stored.
getResponse()public final Reader getResource()
Reader instance ready to process the content of the body of the HTTP response obtained
after invoking getResponse(). A HTTP request will be made to obtain the response if required.
getResource in interface ResourceProvider<Reader>Reader that can be used to consume the body of the resulting HTTP responsepublic final String toString()
toString in class Objectpublic final UrlReaderProvider clone()
getResponse()
clone in class Objectpublic final UrlReaderProvider newRequest(String newUrl)
getResponse()
newUrl - the new URL to be used.
public boolean equals(Object o)
equals in class Objectpublic int hashCode()
hashCode in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||