Interface Resource
- All Known Implementing Classes:
BaseResource
,Resource.PseudoResource
Represents a file type resource in a way that allows where the resource is from to be decoupled from how it is accessed.
For example implementations may fetch remote resources and make the local copy available.
# TODO - add some metadata methods, like size, checksum, cache metadata, anything else? - make it clearer whether the resource is open at this point or not, and whether streams need to be closed
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
static class
A resource that can not be opened but is still useful for identifying some content. -
Field Summary
Modifier and TypeFieldDescriptionstatic final InputStream
An empty input stream for use with UNKNOWNstatic final Resource.Options
Options that will only allow a remote file to be fetched if it can be done over a secure connection.static final Resource
Null alternative for a Resource - use this in place of null where there is no obvious resource to provide as metadata.static final URI
A URI for use with UNKNOWN -
Method Summary
Modifier and TypeMethodDescriptiondefault ResultOrProblems<Path>
ensureLocal
(Resource.Options options) Returns aPath
to a local representation of the resource if the resource loader supports this and is allowable given the options.default String
default Reader
Return aReader
for the underlying resource.Return anInputStream
to the underlying resource.
-
Field Details
-
SECURE_OPTIONS
Options that will only allow a remote file to be fetched if it can be done over a secure connection.
-
UNKNOWN_URI
A URI for use with UNKNOWN
-
NO_BYTES
An empty input stream for use with UNKNOWN
-
UNKNOWN
Null alternative for a Resource - use this in place of null where there is no obvious resource to provide as metadata. Obviously this is not useful if the Resource is going to be open, it's meant as metadata for assisting with messaging etc and clarity in places where no Resource exists.
-
-
Method Details
-
getLocation
URI getLocation()- Returns:
- a
URI
identifying where this resource is located
-
getContentStream
Return an
InputStream
to the underlying resource.Each call should return a freshly created input stream.
- Returns:
- the input stream for the underlying resource.
- Throws:
RiskscapeIOException
-
getContentReader
Return a
Reader
for the underlying resource.A convenience that wraps the result of
#getResourceStream()
in aInputStreamReader
.- Returns:
- reader for the underlying resource
- Throws:
RiskscapeIOException
-
getContentAsString
- Returns:
- a String that is the resource's data read completely in to a string - don't use this on potentially large resources, or you're going to run out of heap
- Throws:
RiskscapeIOException
-
ensureLocal
Returns a
Path
to a local representation of the resource if the resource loader supports this and is allowable given the options. Otherwise problems preventing this operation from succeeding.- Throws:
RiskscapeIOException
- if IO errors occur whilst fetching resource
-
getMediaType
- Returns:
- a media type that represents this resource
-