Class ModuleResource
- All Implemented Interfaces:
InputStreamSource
,Resource
Resource
implementation for Module
resolution,
performing getInputStream()
access via Module.getResourceAsStream(java.lang.String)
.
Alternatively, consider accessing resources in a module path layout via
ClassPathResource
for exported resources, or specifically relative to
a Class
via ClassPathResource(String, Class)
for local resolution within the containing module of that specific class.
In common scenarios, module resources will simply be transparently visible as
classpath resources and therefore do not need any special treatment at all.
- Since:
- 6.1
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
-
Constructor Summary
ConstructorDescriptionModuleResource
(Module module, String path) Create a newModuleResource
for the givenModule
and the given resource path. -
Method Summary
Modifier and TypeMethodDescriptioncreateRelative
(String relativePath) This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.boolean
This implementation compares description strings.Return a description for this resource, to be used for error output when working with the resource.This implementation always returnsnull
, assuming that this resource type does not have a filename.Return anInputStream
for the content of an underlying resource.final Module
Return theModule
for this resource.final String
getPath()
Return the path for this resource.int
hashCode()
This implementation returns the description's hash code.Methods inherited from class org.springframework.core.io.AbstractResource
contentLength, exists, getFile, getFileForLastModifiedCheck, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.io.Resource
getContentAsByteArray, getContentAsString
-
Constructor Details
-
ModuleResource
Create a newModuleResource
for the givenModule
and the given resource path.- Parameters:
module
- the runtime module to search withinpath
- the resource path within the module
-
-
Method Details
-
getModule
Return theModule
for this resource. -
getPath
Return the path for this resource. -
getInputStream
Description copied from interface:InputStreamSource
Return anInputStream
for the content of an underlying resource.It is expected that each call creates a fresh stream.
This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each
getInputStream()
call returns a fresh stream.- Returns:
- the input stream for the underlying resource (must not be
null
) - Throws:
FileNotFoundException
- if the underlying resource does not existIOException
- if the content stream could not be opened- See Also:
-
createRelative
Description copied from class:AbstractResource
This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.- Specified by:
createRelative
in interfaceResource
- Overrides:
createRelative
in classAbstractResource
- Parameters:
relativePath
- the relative path (relative to this resource)- Returns:
- the resource handle for the relative resource
-
getFilename
Description copied from class:AbstractResource
This implementation always returnsnull
, assuming that this resource type does not have a filename.- Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
-
getDescription
Description copied from interface:Resource
Return a description for this resource, to be used for error output when working with the resource.Implementations are also encouraged to return this value from their
toString
method.- See Also:
-
equals
Description copied from class:AbstractResource
This implementation compares description strings.- Overrides:
equals
in classAbstractResource
- See Also:
-
hashCode
public int hashCode()Description copied from class:AbstractResource
This implementation returns the description's hash code.- Overrides:
hashCode
in classAbstractResource
- See Also:
-