| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.core.io.AbstractResource
org.springframework.core.io.ClassPathResource
public class ClassPathResource
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 URL.
ClassLoader.getResourceAsStream(String), 
Class.getResourceAsStream(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 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. | 
|  ClassLoader | getClassLoader()Return the ClassLoader that this resource will be obtained from. | 
|  String | getDescription()This implementation returns a description that includes the class path location. | 
|  File | getFile()This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system. | 
| protected  File | getFileForLastModifiedCheck()This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip). | 
|  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()Return the path for this resource (as resource path within the class path). | 
|  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. | 
| Methods inherited from class org.springframework.core.io.AbstractResource | 
|---|
| exists, getURI, isOpen, isReadable, lastModified, 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(String), 
ClassUtils.getDefaultClassLoader()
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 any| Method Detail | 
|---|
public final String getPath()
public final ClassLoader getClassLoader()
public InputStream getInputStream()
                           throws IOException
IOException - if the stream could not be openedClassLoader.getResourceAsStream(String), 
Class.getResourceAsStream(String)
public URL getURL()
           throws IOException
getURL in interface ResourcegetURL in class AbstractResourceIOException - if the resource cannot be resolved as URL,
 i.e. if the resource is not available as descriptorClassLoader.getResource(String), 
Class.getResource(String)
public File getFile()
             throws IOException
getFile in interface ResourcegetFile in class AbstractResourceIOException - if the resource cannot be resolved as absolute
 file path, i.e. if the resource is not available in a file systemResourceUtils.getFile(java.net.URL, String)
protected File getFileForLastModifiedCheck()
                                    throws IOException
getFileForLastModifiedCheck in class AbstractResourcenull)
IOException - if the resource cannot be resolved as absolute
 file path, i.e. if the resource is not available in a file systempublic Resource createRelative(String relativePath)
createRelative in interface ResourcecreateRelative in class AbstractResourcerelativePath - the relative path (relative to this resource)
StringUtils.applyRelativePath(String, String)public String getFilename()
getFilename in interface ResourcegetFilename in class AbstractResourceStringUtils.getFilename(String)public String getDescription()
Object.toString()public boolean equals(Object obj)
equals in class AbstractResourceResource.getDescription()public int hashCode()
hashCode in class AbstractResourceResource.getDescription()| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||