Top Description Fields Constructors Methods
org.springframework.core.io

public Class ModuleResource

extends AbstractResource
Class Inheritance
Imports
java.io.FileNotFoundException, .IOException, .InputStream, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

Resource implementation for java.lang.Module resolution, performing getInputStream() access via Module#getResourceAsStream.

Alternatively, consider accessing resources in a module path layout via ClassPathResource for exported resources, or specifically relative to a Class via ClassPathResource#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.

Authors
Juergen Hoeller, Sam Brannen
Since
6.1
See Also
Module#getResourceAsStream, ClassPathResource

Field Summary

Modifier and TypeField and Description
private final Module
private final String

Constructor Summary

AccessConstructor and Description
public
ModuleResource(Module
the runtime module to search within
module
,
String
the resource path within the module
path
)

Create a new ModuleResource for the given Module and the given resource path.

Method Summary

Modifier and TypeMethod and Description
public Resource
createRelative(String
the relative path (relative to this resource)
relativePath
)

Overrides org.springframework.core.io.AbstractResource.createRelative.

Implements org.springframework.core.io.Resource.createRelative.

This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides org.springframework.core.io.AbstractResource.equals.

This implementation compares description strings.
public String
getDescription()

Implements org.springframework.core.io.Resource.getDescription.

Return a description for this resource, to be used for error output when working with the resource.
public String
getFilename()

Overrides org.springframework.core.io.AbstractResource.getFilename.

Implements org.springframework.core.io.Resource.getFilename.

This implementation always returns null, assuming that this resource type does not have a filename.
public InputStream
getInputStream()

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Return an InputStream for the content of an underlying resource.
public final Module
getModule()

Return the Module for this resource.

public final String
getPath()

Return the path for this resource.

public int
hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the description's hash code.
Inherited from org.springframework.core.io.AbstractResource:
contentLengthexistsgetFilegetFileForLastModifiedCheckgetURIgetURLisFileisOpenisReadablelastModifiedreadableChanneltoString

Field Detail

moduleback to summary
private final Module module
pathback to summary
private final String path

Constructor Detail

ModuleResourceback to summary
public ModuleResource(Module module, String path)

Create a new ModuleResource for the given Module and the given resource path.

Parameters
module:Module

the runtime module to search within

path:String

the resource path within the module

Method Detail

createRelativeback to summary
public Resource createRelative(String relativePath)

Overrides org.springframework.core.io.AbstractResource.createRelative.

Implements org.springframework.core.io.Resource.createRelative.

Doc from org.springframework.core.io.AbstractResource.createRelative.

This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.

Parameters
relativePath:String

Doc from org.springframework.core.io.Resource.createRelative.

the relative path (relative to this resource)

Returns:Resource

Doc from org.springframework.core.io.Resource.createRelative.

the resource handle for the relative resource

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides org.springframework.core.io.AbstractResource.equals.

Doc from org.springframework.core.io.AbstractResource.equals.

This implementation compares description strings.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDescriptionback to summary
public String getDescription()

Implements org.springframework.core.io.Resource.getDescription.

Doc from org.springframework.core.io.Resource.getDescription.

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.

Annotations
@Override
getFilenameback to summary
public String getFilename()

Overrides org.springframework.core.io.AbstractResource.getFilename.

Implements org.springframework.core.io.Resource.getFilename.

Doc from org.springframework.core.io.AbstractResource.getFilename.

This implementation always returns null, assuming that this resource type does not have a filename.

Annotations
@Override
@Nullable
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

Return an InputStream 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:InputStream

the input stream for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:
if the content stream could not be opened
getModuleback to summary
public final Module getModule()

Return the Module for this resource.

getPathback to summary
public final String getPath()

Return the path for this resource.

hashCodeback to summary
public int hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

Doc from org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the description's hash code.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override