public class MockWebResourceFetcher extends Object implements WebResourceFetcher
WebResourceFetcher
.Modifier and Type | Field and Description |
---|---|
HashMap<String,byte[]> |
webResources |
Constructor and Description |
---|
MockWebResourceFetcher()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
InputStream |
getInputStreamForUrl(String urlString)
Returns an InputStream for the document at the given URL.
|
void |
setReturnFailingReaders(boolean returnFailingReaders)
When set to true, every operation that returns reader or stream objects
to access some resource will return objects that fail with exceptions
when trying to read data.
|
void |
setWebResourceContents(String url,
String contents)
Defines the contents of a new web resource.
|
void |
setWebResourceContents(String url,
String contents,
CompressionType compressionType)
Defines the contents of a new web resource.
|
void |
setWebResourceContentsFromResource(String url,
String resource,
Class<?> resourceClass)
Defines the contents of a new web resource by taking the string from a
given (Java) resource.
|
void |
setWebResourceContentsFromResource(String url,
String resource,
Class<?> resourceClass,
CompressionType compressionType)
Defines the contents of a new web resource by taking the string from a
given (Java) resource, possibly using additional compression.
|
public void setReturnFailingReaders(boolean returnFailingReaders)
returnFailingReaders
- whether read operations should failpublic void setWebResourceContents(String url, String contents) throws IOException
url
- the URL stringcontents
- the string contentsIOException
public void setWebResourceContents(String url, String contents, CompressionType compressionType) throws IOException
url
- the URL stringcontents
- the string contentscompressionType
- the compression to use on the mocked contentsIOException
public void setWebResourceContentsFromResource(String url, String resource, Class<?> resourceClass) throws IOException
url
- the URL stringresource
- the Java resource nameresourceClass
- the Class relative to which the resource should be resolved
(since resources are stored relative to a classpath); can
usually be obtained with getClass() from the calling objectIOException
- if the Java resource could not be loadedpublic void setWebResourceContentsFromResource(String url, String resource, Class<?> resourceClass, CompressionType compressionType) throws IOException
url
- the URL stringresource
- the Java resource nameresourceClass
- the Class relative to which the resource should be resolved
(since resources are stored relative to a classpath); can
usually be obtained with getClass() from the calling objectcompressionType
- the compression to use on the mocked contentsIOException
- if the Java resource could not be loadedpublic InputStream getInputStreamForUrl(String urlString) throws IOException
WebResourceFetcher
getInputStreamForUrl
in interface WebResourceFetcher
urlString
- the URL of the documentIOException
- if the document at the URL could not be opened or the URL was
invalidCopyright © 2014–2024 Wikidata Toolkit Developers. Generated from source code published under the Apache License 2.0. For more information, see the Wikidata Toolkit homepage