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
ConstructorsConstructorDescriptionModuleResource(Module module, String path) Create a newModuleResourcefor the givenModuleand 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.booleanThis 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 anInputStreamfor the content of an underlying resource.final ModuleReturn theModulefor this resource.final StringgetPath()Return the path for this resource.inthashCode()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, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.Resource
getContentAsByteArray, getContentAsString
-
Constructor Details
-
ModuleResource
Create a newModuleResourcefor the givenModuleand the given resource path.- Parameters:
module- the runtime module to search withinpath- the resource path within the module
-
-
Method Details
-
getModule
Return theModulefor this resource. -
getPath
Return the path for this resource. -
getInputStream
Description copied from interface:InputStreamSourceReturn anInputStreamfor 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:AbstractResourceThis implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classAbstractResource- Parameters:
relativePath- the relative path (relative to this resource)- Returns:
- the resource handle for the relative resource
-
getFilename
Description copied from class:AbstractResourceThis implementation always returnsnull, assuming that this resource type does not have a filename.- Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource
-
getDescription
Description copied from interface:ResourceReturn 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
toStringmethod.- See Also:
-
equals
Description copied from class:AbstractResourceThis implementation compares description strings.- Overrides:
equalsin classAbstractResource- See Also:
-
hashCode
public int hashCode()Description copied from class:AbstractResourceThis implementation returns the description's hash code.- Overrides:
hashCodein classAbstractResource- See Also:
-