Resource implementation for class path resources. Uses either a
given ClassLoader or a given Class for loading resources.
Supports resolution as java.io.File if the class path
resource resides in the file system, but not for resources in a JAR.
Always supports resolution as java.net.URL.
ClassLoader#getResourceAsStream(String), ClassLoader#getResource(String), Class#getResourceAsStream(String), Class#getResource(String)
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private final ClassLoader | |
| private final Class | |
| private final String | path
Internal representation of the original path supplied by the user, used for creating relative paths and resolving URLs and InputStreams. |
| Access | Constructor and Description |
|---|---|
| public | ClassPathResource(String
the absolute path within the class path path)Create a new |
| public | ClassPathResource(String
the absolute path within the class path path, ClassLoader the class loader to load the resource with classLoader)Create a new |
| public | ClassPathResource(String
relative or absolute path within the class path path, Class<?> the class to load resources with clazz)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public Resource | createRelative(String
the relative path (relative to this resource) relativePath)Overrides org. Implements org. ClassPathResource, applying the given
path relative to the path used to create this descriptor.
|
| public boolean | equals(Object
the reference object with which to compare. other)Overrides org. |
| public boolean | exists()
Overrides org. Implements org. |
| public final ClassLoader | |
| public String | getDescription()
Implements org. |
| public String | getFilename()
Overrides org. Implements org. |
| public InputStream | getInputStream()
Implements org. InputStream for the underlying class
path resource, if available.
|
| public final String | |
| public URL | getURL()
Overrides org. Implements org. |
| public int | hashCode()
Overrides org. |
| public boolean | isReadable()
Overrides org. Overrides default org. AbstractFileResolvingResource's length check.
|
| protected URL | Returns: the resolved URL, ornull if not resolvableResolves a |
| absolutePath | back to summary |
|---|---|
| private final String absolutePath | |
| classLoader | back to summary |
|---|---|
| private final ClassLoader classLoader
| |
| clazz | back to summary |
|---|---|
| private final Class<?> clazz
| |
| path | back to summary |
|---|---|
| private final String path Internal representation of the original path supplied by the user, used for creating relative paths and resolving URLs and InputStreams. | |
| ClassPathResource | back to summary |
|---|---|
| public ClassPathResource(String path) Create a new A leading slash will be removed, as the The default class loader will be used for loading the resource.
| |
| ClassPathResource | back to summary |
|---|---|
| public ClassPathResource(String path, ClassLoader classLoader) Create a new A leading slash will be removed, as the If the supplied
| |
| ClassPathResource | back to summary |
|---|---|
| public ClassPathResource(String path, Class<?> clazz) Create a new The path can be relative to the given class, or absolute within the class path via a leading slash. If the supplied This is also useful for resource access within the module system,
loading a resource from the containing module of a given
| |
| createRelative | back to summary |
|---|---|
| public Resource createRelative(String relativePath) Overrides org. Implements org. This implementation creates a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides org. This implementation compares the underlying class path locations and associated class loaders.
| |
| exists | back to summary |
|---|---|
| public boolean exists() Overrides org. Implements org. This implementation checks for the resolution of a resource URL.
| |
| getClassLoader | back to summary |
|---|---|
| public final ClassLoader getClassLoader() Return the
| |
| getDescription | back to summary |
|---|---|
| public String getDescription() Implements org. This implementation returns a description that includes the absolute class path location.
| |
| getFilename | back to summary |
|---|---|
| public String getFilename() Overrides org. Implements org. This implementation returns the name of the file that this class path resource refers to.
| |
| getInputStream | back to summary |
|---|---|
| public InputStream getInputStream() throws IOException Implements org. This implementation opens an
| |
| getPath | back to summary |
|---|---|
| public final String getPath() Return the absolute path for this resource, as a cleaned resource path within the class path. The path returned by this method does not have a leading slash and is
suitable for use with | |
| getURL | back to summary |
|---|---|
| public URL getURL() throws IOException Overrides org. Implements org. This implementation returns a URL for the underlying class path resource, if available.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides org. This implementation returns the hash code of the underlying class path location.
| |
| isReadable | back to summary |
|---|---|
| public boolean isReadable() Overrides org. Overrides default org. This implementation checks for the resolution of a resource URL upfront,
then proceeding with
| |
| resolveURL | back to summary |
|---|---|
| protected URL resolveURL() Resolves a | |