Package net.sf.saxon.resource
Class BinaryResource
- java.lang.Object
-
- net.sf.saxon.resource.BinaryResource
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceFactory
FACTORY
ResourceFactory suitable for creating a BinaryResource
-
Constructor Summary
Constructors Constructor Description BinaryResource(java.lang.String href, java.lang.String contentType, byte[] content)
Create a binary resource supplying the actual content as a byte arrayBinaryResource(AbstractResourceCollection.InputDetails in)
Create a binary resource
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
decode(byte[] value, int offset, int len, java.lang.String encoding)
static java.lang.String
decode(byte[] value, java.lang.String encoding)
static byte[]
encode(java.lang.String s, java.lang.String encoding)
static void
error(java.lang.String message)
Throw an errorjava.lang.String
getContentType()
Get the media type (MIME type) of the resource if known, for example "image/jpeg".byte[]
getData()
Get the content of the resource as an array of bytesBase64BinaryValue
getItem()
Get an XDM Item holding the contents of this resource.java.lang.String
getResourceURI()
Get the URI of the resourcestatic byte[]
readBinaryFromStream(java.io.InputStream in, java.lang.String path)
Utility method to construct an array of bytes from the content of an InputStreamvoid
setData(byte[] data)
Set the content of the resource as an array of bytes
-
-
-
Field Detail
-
FACTORY
public static final ResourceFactory FACTORY
ResourceFactory suitable for creating a BinaryResource
-
-
Constructor Detail
-
BinaryResource
public BinaryResource(AbstractResourceCollection.InputDetails in)
Create a binary resource- Parameters:
in
- details about the resource
-
BinaryResource
public BinaryResource(java.lang.String href, java.lang.String contentType, byte[] content)
Create a binary resource supplying the actual content as a byte array- Parameters:
href
- the URI of the resourcecontentType
- the media typecontent
- the actual content as a byte array
-
-
Method Detail
-
encode
public static byte[] encode(java.lang.String s, java.lang.String encoding) throws XPathException
- Throws:
XPathException
-
decode
public static java.lang.String decode(byte[] value, java.lang.String encoding) throws XPathException
- Throws:
XPathException
-
decode
public static java.lang.String decode(byte[] value, int offset, int len, java.lang.String encoding) throws XPathException
- Throws:
XPathException
-
error
public static void error(java.lang.String message) throws XPathException
Throw an error- Parameters:
message
- the error message- Throws:
XPathException
- always
-
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 java.lang.String getResourceURI()
Get the URI of the resource- Specified by:
getResourceURI
in interfaceResource
- Returns:
- the URI of the resource
-
readBinaryFromStream
public static byte[] readBinaryFromStream(java.io.InputStream in, java.lang.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 Base64BinaryValue getItem() throws XPathException
Get an XDM Item holding the contents of this resource.- Specified by:
getItem
in interfaceResource
- Returns:
- an item holding the contents of the resource. For a binary resource
the value will always be a
Base64BinaryValue
. This does not mean that the content is actually encoded in Base64 internally; rather it means that when converted to a string, the content is presented in Base64 encoding. - Throws:
XPathException
- if a failure occurs materializing the resource
-
getContentType
public java.lang.String getContentType()
Get the media type (MIME type) of the resource if known, for example "image/jpeg".- Specified by:
getContentType
in interfaceResource
- Returns:
- the media type if known; otherwise null
-
-