Class Resource
- java.lang.Object
-
- org.xmlresolver.Resource
-
public class Resource extends java.lang.Object
Represents a web 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
Constructors Constructor Description Resource(java.io.InputStream stream, java.net.URI uri, java.net.URI localURI)
Creates a new instance of Resource.Resource(java.io.InputStream stream, java.net.URI uri, java.net.URI localURI, java.lang.String contentType)
Creates a new instance of Resource.Resource(java.lang.String href)
Creates a new instance of Resource from just a URI.Resource(java.net.URI href)
Creates a new instance of Resource from just a URI.Resource(ResolverConfiguration config, java.lang.String href)
Creates a new instance of Resource from just a URI.Resource(ResolverConfiguration config, java.net.URI href)
Creates a new instance of Resource from just a URI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStream
body()
Return the InputStream associated with the resource.java.lang.String
contentType()
Return the MIME content type associated with the resource.java.net.URI
localUri()
Return the local URI associated with the resource.java.net.URI
uri()
Return the URI associated with the resource.
-
-
-
Constructor Detail
-
Resource
public Resource(java.io.InputStream stream, java.net.URI uri, java.net.URI localURI)
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
public Resource(java.io.InputStream stream, java.net.URI uri, java.net.URI localURI, java.lang.String contentType)
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
public Resource(java.lang.String href) throws java.io.IOException, java.net.URISyntaxException
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:
java.io.IOException
- for I/O errorsjava.net.URISyntaxException
- if the href cannot be converted to a URI
-
Resource
public Resource(ResolverConfiguration config, java.lang.String href) throws java.io.IOException, java.net.URISyntaxException
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:
java.io.IOException
- for I/O errorsjava.net.URISyntaxException
- if the href cannot be converted to a URI
-
Resource
public Resource(java.net.URI href) throws java.io.IOException, java.net.URISyntaxException
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:
java.io.IOException
- for I/O errorsjava.net.URISyntaxException
- if the href cannot be converted to a URI
-
Resource
public Resource(ResolverConfiguration config, java.net.URI href) throws java.io.IOException, java.net.URISyntaxException
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:
java.io.IOException
- for I/O errorsjava.net.URISyntaxException
- if the href cannot be converted to a URI
-
-
Method Detail
-
body
public java.io.InputStream 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
public java.net.URI 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
public java.net.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
public java.lang.String contentType()
Return the MIME content type associated with the resource.- Returns:
- The content type
-
-