Class Resource

java.lang.Object
org.xmlresolver.Resource

public class Resource extends 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 Details

    • Resource

      public Resource(InputStream stream, URI uri, URI localURI)
      Creates a new instance of Resource.
      Parameters:
      stream - The stream from which the resource can be read
      uri - The URI
      localURI - The local URI, irrespective of what will be reported as the URI.
    • Resource

      public Resource(InputStream stream, URI uri, URI localURI, String contentType)
      Creates a new instance of Resource.
      Parameters:
      stream - The stream from which the resource can be read
      uri - The URI
      localURI - The local URI, irrespective of what will be reported as the URI.
      contentType - The content type
    • Resource

      public Resource(String href) throws IOException, 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 the XmlLoader and ValidatingXmlLoader. When possible, pass the resolver configuration to the constructor.

      Parameters:
      href - The URI
      Throws:
      IOException - for I/O errors
      URISyntaxException - if the href cannot be converted to a URI
    • Resource

      public Resource(ResolverConfiguration config, String href) throws IOException, 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:
      IOException - for I/O errors
      URISyntaxException - if the href cannot be converted to a URI
    • Resource

      public Resource(URI href) throws IOException, 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 the XmlLoader and ValidatingXmlLoader. When possible, pass the resolver configuration to the constructor.

      Parameters:
      href - The URI
      Throws:
      IOException - for I/O errors
      URISyntaxException - if the href cannot be converted to a URI
    • Resource

      public Resource(ResolverConfiguration config, URI href) throws IOException, 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:
      IOException - for I/O errors
      URISyntaxException - if the href cannot be converted to a URI
  • Method Details

    • body

      public 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 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 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 String contentType()
      Return the MIME content type associated with the resource.
      Returns:
      The content type