Class Resource
An web resource consists of an absolute URI, an input stream, and a MIME content type.
In some circumstances, such as when the initial URI is a file:
URI, the
content type may be unknown (null
).
-
Constructor Summary
ConstructorsConstructorDescriptionResource
(InputStream stream, URI uri, URI localURI) Creates a new instance of Resource.Resource
(InputStream stream, URI uri, URI localURI, String contentType) Creates a new instance of Resource.Creates a new instance of Resource from just a URI.Creates a new instance of Resource from just a URI.Resource
(ResolverConfiguration config, String href) Creates a new instance of Resource from just a URI.Resource
(ResolverConfiguration config, URI href) Creates a new instance of Resource from just a URI. -
Method Summary
-
Constructor Details
-
Resource
Creates a new instance of Resource.- Parameters:
stream
- The stream from which the resource can be readuri
- The URIlocalURI
- The local URI, irrespective of what will be reported as the URI.
-
Resource
Creates a new instance of Resource.- Parameters:
stream
- The stream from which the resource can be readuri
- The URIlocalURI
- The local URI, irrespective of what will be reported as the URI.contentType
- The content type
-
Resource
Creates a new instance of Resource from just a URI.This version has to use the default class loader to access
classpath:
URIs. It is used by the zero-argument constructors for theXmlLoader
andValidatingXmlLoader
. When possible, pass the resolver configuration to the constructor.- Parameters:
href
- The URI- Throws:
IOException
- for I/O errorsURISyntaxException
- if the href cannot be converted to a URI
-
Resource
Creates a new instance of Resource from just a URI.This version will use the configured class loader to access
classpath:
URIs.- Parameters:
config
- The configuration (used to get the classloader)href
- The URI- Throws:
IOException
- for I/O errorsURISyntaxException
- if the href cannot be converted to a URI
-
Resource
Creates a new instance of Resource from just a URI.This version has to use the default class loader to access
classpath:
URIs. It is used by the zero-argument constructors for theXmlLoader
andValidatingXmlLoader
. When possible, pass the resolver configuration to the constructor.- Parameters:
href
- The URI- Throws:
IOException
- for I/O errorsURISyntaxException
- if the href cannot be converted to a URI
-
Resource
Creates a new instance of Resource from just a URI.This version will use the configured class loader to access
classpath:
URIs.- Parameters:
config
- The configuration (used to get the classloader)href
- The URI- Throws:
IOException
- for I/O errorsURISyntaxException
- if the href cannot be converted to a URI
-
-
Method Details
-
body
Return the InputStream associated with the resource.The stream returned is the actual stream used when creating the resource. Reading from this stream changes the resource.
- Returns:
- The stream
-
uri
Return the URI associated with the resource.For resources that are cached, or from a jar file, this may be the "original" URI instead of the actually resolved URI.
- Returns:
- The URI
-
localUri
Return the local URI associated with the resource.This is always the local URI, whether it's from a jar file or from the cache.
- Returns:
- The URI
-
contentType
Return the MIME content type associated with the resource.- Returns:
- The content type
-