Package org.wikidata.wdtk.util
Class WebResourceFetcherImpl
java.lang.Object
org.wikidata.wdtk.util.WebResourceFetcherImpl
- All Implemented Interfaces:
WebResourceFetcher
Standard implementation of
WebResourceFetcher
.- Author:
- Markus Kroetzsch
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetInputStreamForUrl
(String urlString) Returns an InputStream for the document at the given URL.static Proxy
getProxy()
Returns the proxy that will be used for all requests made by Wikidata Toolkit.static URLConnection
getUrlConnection
(URL url) Opens a basic URL connection for the given URL and performs basic configurations.static String
Returns the string that will be used to identify the user agent on all requests made by Wikidata Toolkit.static boolean
hasProxy()
Checks whether a proxy is set.static void
Sets the proxy that will be used for alle requests made by Wikidata Toolkit.static void
setUserAgent
(String userAgent) Sets the string that will be used to identify the user agent on all requests made by Wikidata Toolkit.
-
Field Details
-
userAgent
-
proxy
-
-
Constructor Details
-
WebResourceFetcherImpl
public WebResourceFetcherImpl()
-
-
Method Details
-
getProxy
Returns the proxy that will be used for all requests made by Wikidata Toolkit.- Returns:
- the proxy represented as java object
-
setProxy
Sets the proxy that will be used for alle requests made by Wikidata Toolkit. This should be set in own tools based on Wikidata Toolkit esp. when making large amounts of requests.- Parameters:
proxy
- the proxy represented as java object
-
hasProxy
public static boolean hasProxy()Checks whether a proxy is set.- Returns:
- True if a proxy is set, false, if there isn't set any proxy.
-
getUserAgent
Returns the string that will be used to identify the user agent on all requests made by Wikidata Toolkit.- Returns:
- the user agent string
-
setUserAgent
Sets the string that will be used to identify the user agent on all requests made by Wikidata Toolkit. This should be set in own tools based on Wikidata Toolkit esp. when making large amounts of requests.- Parameters:
userAgent
- the user agent string
-
getUrlConnection
Opens a basic URL connection for the given URL and performs basic configurations. In particular, it will set the User-Agent. The current proxy settings are also respected. For http(s) URLs, the result is aHttpURLConnection
.- Parameters:
url
- the URL to open- Returns:
- the URL connection to access this URL
- Throws:
IOException
-
getInputStreamForUrl
Description copied from interface:WebResourceFetcher
Returns an InputStream for the document at the given URL. This can be used for downloading. The stream should be closed after use.- Specified by:
getInputStreamForUrl
in interfaceWebResourceFetcher
- Parameters:
urlString
- the URL of the document- Returns:
- InputStream for the requested document
- Throws:
IOException
- if the document at the URL could not be opened or the URL was invalid
-