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
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic classA resource that can not be opened but is still useful for identifying some content. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final InputStreamAn empty input stream for use with UNKNOWNstatic final Resource.OptionsOptions that will only allow a remote file to be fetched if it can be done over a secure connection.static final ResourceNull alternative for a Resource - use this in place of null where there is no obvious resource to provide as metadata.static final URIA URI for use with UNKNOWN -
Method Summary
Modifier and TypeMethodDescriptiondefault ResultOrProblems<Path>ensureLocal(Resource.Options options) Returns aPathto a local representation of the resource if the resource loader supports this and is allowable given the options.default ResultOrProblems<Path>ensureLocal(Resource.Options secureOptions, String fileExtension) default Stringdefault ReaderReturn aReaderfor the underlying resource.Return anInputStreamto the underlying resource.getLocal()Alternative toensureLocal(nz.org.riskscape.engine.resource.Resource.Options, java.lang.String)that will only return the local path if the resource already exists there.
-
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
URIidentifying where this resource is located
-
getContentStream
Return an
InputStreamto 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
Readerfor 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
-
ensureLocal
Returns a
Pathto 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
-
getLocal
Alternative to
ensureLocal(nz.org.riskscape.engine.resource.Resource.Options, java.lang.String)that will only return the local path if the resource already exists there.- Returns:
- the path to the resource on the local path or empty if the resource does not exist locally already
-
getMediaType
- Returns:
- a media type that represents this resource
-