public class ClassPathResource extends AbstractFileResolvingResource
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 URL.
ClassLoader.getResourceAsStream(String)
,
Class.getResourceAsStream(String)
Modifier | Constructor and Description |
---|---|
|
ClassPathResource(String path)
Create a new ClassPathResource for ClassLoader usage.
|
|
ClassPathResource(String path,
Class<?> clazz)
Create a new ClassPathResource for Class usage.
|
|
ClassPathResource(String path,
ClassLoader classLoader)
Create a new ClassPathResource for ClassLoader usage.
|
protected |
ClassPathResource(String path,
ClassLoader classLoader,
Class<?> clazz)
Create a new ClassPathResource with optional ClassLoader and Class.
|
Modifier and Type | Method and Description |
---|---|
Resource |
createRelative(String relativePath)
This implementation creates a ClassPathResource, applying the given path
relative to the path of the underlying resource of this descriptor.
|
boolean |
equals(Object obj)
This implementation compares the underlying class path locations.
|
boolean |
exists()
This implementation checks for the resolution of a resource URL.
|
ClassLoader |
getClassLoader() |
String |
getDescription()
This implementation returns a description that includes the class path location.
|
String |
getFilename()
This implementation returns the name of the file that this class path
resource refers to.
|
InputStream |
getInputStream()
This implementation opens an InputStream for the given class path resource.
|
String |
getPath() |
URI |
getURI() |
URL |
getURL()
This implementation returns a URL for the underlying class path resource.
|
int |
hashCode()
This implementation returns the hash code of the underlying
class path location.
|
contentLength, getFile, getFile, getFileForLastModifiedCheck, isReadable, lastModified
public ClassPathResource(String path)
The thread context class loader will be used for loading the resource.
path
- the absolute path within the class pathClassLoader.getResourceAsStream(String)
public ClassPathResource(String path, ClassLoader classLoader)
path
- the absolute path within the classpathclassLoader
- the class loader to load the resource with,
or null
for the thread context class loaderClassLoader.getResourceAsStream(String)
public ClassPathResource(String path, Class<?> clazz)
path
- relative or absolute path within the class pathclazz
- the class to load resources withClass.getResourceAsStream(java.lang.String)
protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz)
path
- relative or absolute path within the classpathclassLoader
- the class loader to load the resource with, if anyclazz
- the class to load resources with, if anypublic final String getPath()
public final ClassLoader getClassLoader()
public boolean exists()
exists
in interface Resource
exists
in class AbstractFileResolvingResource
ClassLoader.getResource(String)
,
Class.getResource(String)
public InputStream getInputStream() throws IOException
IOException
- if there is an errorClassLoader.getResourceAsStream(String)
,
Class.getResourceAsStream(String)
public URL getURL() throws IOException
IOException
- if the resource cannot be resolved as URL,
i.e. if the resource is not available as descriptorClassLoader.getResource(String)
,
Class.getResource(String)
public URI getURI() throws IOException
IOException
- if the resource cannot be resolved as URI,
i.e. if the resource is not available as descriptorpublic Resource createRelative(String relativePath)
relativePath
- The relative pathpublic String getFilename()
public String getDescription()
Object.toString()
public boolean equals(Object obj)