Class DefaultResourceLoader.ClassPathAllResource
java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.AbstractFileResolvingResource
org.springframework.core.io.ClassPathResource
org.springframework.core.io.DefaultResourceLoader.ClassPathAllResource
- All Implemented Interfaces:
InputStreamSource, Resource
- Enclosing class:
DefaultResourceLoader
A multi-content ClassPathResource handle that can expose the content
from all matching resources in the classpath.
- Since:
- 7.1
- Author:
- Juergen Hoeller
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconsumeContent(IOConsumer<InputStream> consumer) Process the contents of this resource through the given consumer callback.longThis method reads the entire InputStream to determine the content length.createRelative(String relativePath) This implementation creates aClassPathResource, applying the given path relative to the path used to create this descriptor.This implementation returns a description that includes the absolute class path location.This implementation opens anInputStreamfor the underlying class path resource, if available.getURL()This implementation returns a URL for the underlying class path resource, if available.booleanisFile()This implementation always returnsfalse.Methods inherited from class ClassPathResource
equals, exists, getClassLoader, getFilename, getPath, hashCode, isReadable, resolveURLMethods inherited from class AbstractFileResolvingResource
customizeConnection, customizeConnection, getFile, getFile, getFileForLastModifiedCheck, isFile, lastModified, readableChannelMethods inherited from class AbstractResource
getURI, isOpen, toStringMethods inherited from interface Resource
getContentAsByteArray, getContentAsString, getFilePath
-
Constructor Details
-
ClassPathAllResource
-
-
Method Details
-
isFile
public boolean isFile()Description copied from class:AbstractResourceThis implementation always returnsfalse.- Specified by:
isFilein interfaceResource- Overrides:
isFilein classAbstractFileResolvingResource- See Also:
-
getURL
Description copied from class:ClassPathResourceThis implementation returns a URL for the underlying class path resource, if available.- Specified by:
getURLin interfaceResource- Overrides:
getURLin classClassPathResource- Throws:
IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor- See Also:
-
contentLength
Description copied from class:AbstractResourceThis method reads the entire InputStream to determine the content length.For a custom subclass of
InputStreamResource, we strongly recommend overriding this method with a more optimal implementation, for example, checking File length, or possibly simply returning -1 if the stream can only be read once.- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classAbstractFileResolvingResource- Returns:
- the content length (or -1 if undetermined)
- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- See Also:
-
getInputStream
Description copied from class:ClassPathResourceThis implementation opens anInputStreamfor the underlying class path resource, if available.- Specified by:
getInputStreamin interfaceInputStreamSource- Overrides:
getInputStreamin classClassPathResource- Returns:
- the input stream for the underlying resource (must not be
null) - Throws:
IOException- if the content stream could not be opened- See Also:
-
consumeContent
Description copied from interface:ResourceProcess the contents of this resource through the given consumer callback.The given consumer will be invoked a single time by default - but may also be invoked multiple times in case of a multi-content resource handle, for example returned from a
getResource("classpath*:...")call. WhileInputStreamSource.getInputStream()returns a merged sequence of content in such a case, this method performs one callback per file content.- Parameters:
consumer- a consumer for each InputStream- Throws:
IOException- in case of general resolution/reading failures- See Also:
-
createRelative
Description copied from class:ClassPathResourceThis implementation creates aClassPathResource, applying the given path relative to the path used to create this descriptor.- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classClassPathResource- Parameters:
relativePath- the relative path (relative to this resource)- Returns:
- the resource handle for the relative resource
- See Also:
-
getDescription
Description copied from class:ClassPathResourceThis implementation returns a description that includes the absolute class path location.- Specified by:
getDescriptionin interfaceResource- Overrides:
getDescriptionin classClassPathResource- See Also:
-