public class Resource extends Object
<d:file> in XProc.
This class is immutable.| Modifier and Type | Field and Description |
|---|---|
static String |
MEDIA_TYPE_UNKNOWN |
| Modifier | Constructor and Description |
|---|---|
protected |
Resource(File from,
URI path,
Optional<String> mediaType) |
| Modifier and Type | Method and Description |
|---|---|
Resource |
copy(File path) |
Resource |
copy(URI path) |
Optional<String> |
getMediaType() |
URI |
getPath()
The path as a URI.
|
URI |
getPath(URI base)
The path as a URI relative to the given base URI.
|
static Resource |
load(byte[] data,
URI path,
String mediaType) |
static Resource |
load(File from,
String mediaType) |
static Resource |
load(File from,
URI path,
String mediaType) |
static Resource |
load(InputStream data,
URI path,
String mediaType) |
static Resource |
load(Supplier<InputStream> data,
URI path,
String mediaType) |
static Resource |
load(URI from,
String mediaType) |
static Resource |
load(URI from,
URI path,
String mediaType) |
InputStream |
read()
Get the contents of the resource as an
InputStream. |
File |
readAsFile()
If this resource is stored on disk or was loaded from disk, return the path as a
File. |
Source |
readAsSource()
If this resource is stored on disk, return the absolute file path as a
Source. |
Resource |
store()
Store file to disk
|
public static final String MEDIA_TYPE_UNKNOWN
public URI getPath()
public static Resource load(URI from, String mediaType)
from - Must be an absolute, hierarchical URI with a scheme equal to "file",
a non-empty path component, and undefined authority, query, and
fragment components.IllegalArgumentException - if the URI does not point to a file on disk.public static Resource load(InputStream data, URI path, String mediaType)
public static Resource load(Supplier<InputStream> data, URI path, String mediaType)
data - data.get() is called only once.public InputStream read() throws IOException
InputStream.IOExceptionpublic File readAsFile() throws UnsupportedOperationException
File.
May be different from getPath() if the file was copied from an original location.UnsupportedOperationExceptionpublic Source readAsSource() throws IOException
Source.
Otherwise, return the data stream as a Source with a non-empty system ID.IOExceptionpublic Resource store() throws IOException
IOException - if "path" does not point to a file on disk or if the file can not be
written to.Copyright © 2010–2026 The DAISY Consortium. All rights reserved.