|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.io.AbstractResource org.springframework.core.io.ClassPathResource
Resource implementation for class path resources. Uses either the thread context class loader, 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 URL.
Thread.getContextClassLoader()
,
ClassLoader.getResourceAsStream(java.lang.String)
,
Class.getResourceAsStream(java.lang.String)
Constructor Summary | |
|
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. |
Method Summary | |
Resource |
createRelative(String relativePath)
This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource. |
boolean |
equals(Object obj)
This implementation compares description strings. |
String |
getDescription()
Return a description for this resource, to be used for error output when working with the resource. |
File |
getFile()
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path. |
String |
getFilename()
This implementation always throws IllegalStateException, assuming that the resource does not carry a filename. |
InputStream |
getInputStream()
Return an InputStream. |
URL |
getURL()
This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL. |
int |
hashCode()
This implementation returns the description's hash code. |
Methods inherited from class org.springframework.core.io.AbstractResource |
exists, isOpen, toString |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
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(java.lang.String)
,
Thread.getContextClassLoader()
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(java.lang.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 anyMethod Detail |
public InputStream getInputStream() throws IOException
InputStreamSource
IOException
- if the stream could not be openedpublic URL getURL() throws IOException
AbstractResource
getURL
in interface Resource
getURL
in class AbstractResource
IOException
public File getFile() throws IOException
AbstractResource
getFile
in interface Resource
getFile
in class AbstractResource
IOException
public Resource createRelative(String relativePath)
AbstractResource
createRelative
in interface Resource
createRelative
in class AbstractResource
public String getFilename()
AbstractResource
getFilename
in interface Resource
getFilename
in class AbstractResource
public String getDescription()
Resource
Implementations are also encouraged to return this value from their toString method.
Object.toString()
public boolean equals(Object obj)
AbstractResource
equals
in class AbstractResource
Resource.getDescription()
public int hashCode()
AbstractResource
hashCode
in class AbstractResource
Resource.getDescription()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |