Class BinaryResource

java.lang.Object
net.sf.saxon.resource.BinaryResource
All Implemented Interfaces:
Resource

public class BinaryResource extends Object implements Resource
  • Field Details

    • FACTORY

      public static final ResourceFactory FACTORY
      ResourceFactory suitable for creating a BinaryResource
  • Constructor Details

  • Method Details

    • setData

      public void setData(byte[] data)
      Set the content of the resource as an array of bytes
      Parameters:
      data - the content of the resource
    • getData

      public byte[] getData()
      Get the content of the resource as an array of bytes
      Returns:
      the content (if it has been set using setData())
    • getResourceURI

      public String getResourceURI()
      Get the URI of the resource
      Specified by:
      getResourceURI in interface Resource
      Returns:
      the URI of the resource
    • readBinaryFromStream

      public static byte[] readBinaryFromStream(InputStream in, String path) throws XPathException
      Utility method to construct an array of bytes from the content of an InputStream
      Parameters:
      in - the input stream. The method consumes the input stream but does not close it.
      path - file name or URI used only for diagnostics
      Returns:
      byte array representing the content of the InputStream
      Throws:
      XPathException - if a failure occurs obtaining a connection or reading the stream
    • getItem

      public Item getItem(XPathContext context) throws XPathException
      Description copied from interface: Resource
      Get an XDM Item holding the contents of this resource.
      Specified by:
      getItem in interface Resource
      Parameters:
      context - the XPath evaluation context
      Returns:
      an item holding the contents of the resource. The type of item will reflect the type of the resource: a document node for XML resources, a string for text resources, a map or array for JSON resources, a base64Binary value for binary resource. May also return null if the resource cannot be materialized and this is not to be treated as an error.
      Throws:
      XPathException - if a failure occurs materializing the resource
    • getContentType

      public String getContentType()
      Description copied from interface: Resource
      Get the media type (MIME type) of the resource if known
      Specified by:
      getContentType in interface Resource
      Returns:
      the media type if known; otherwise null