Save This Page
Home » spring-framework-2.5.4 » org.springframework » core » io » [javadoc | source]
org.springframework.core.io
public class: ClassPathResource [javadoc | source]
java.lang.Object
   org.springframework.core.io.AbstractResource
      org.springframework.core.io.ClassPathResource

All Implemented Interfaces:
    Resource

Direct Known Subclasses:
    ClassPathContextResource

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.

Constructor:
 public ClassPathResource(String path) 
    Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.

    The thread context class loader will be used for loading the resource.

    Parameters:
    path - the absolute path within the class path
    Also see:
    java.lang.ClassLoader#getResourceAsStream(String)
    org.springframework.util.ClassUtils#getDefaultClassLoader()
 public ClassPathResource(String path,
    ClassLoader classLoader) 
    Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.
    Parameters:
    path - the absolute path within the classpath
    classLoader - the class loader to load the resource with, or null for the thread context class loader
    Also see:
    java.lang.ClassLoader#getResourceAsStream(String)
 public ClassPathResource(String path,
    Class clazz) 
    Create a new ClassPathResource for Class usage. The path can be relative to the given class, or absolute within the classpath via a leading slash.
    Parameters:
    path - relative or absolute path within the class path
    clazz - the class to load resources with
    Also see:
    java.lang.Class#getResourceAsStream
 protected ClassPathResource(String path,
    ClassLoader classLoader,
    Class clazz) 
    Create a new ClassPathResource with optional ClassLoader and Class. Only for internal usage.
    Parameters:
    path - relative or absolute path within the classpath
    classLoader - the class loader to load the resource with, if any
    clazz - the class to load resources with, if any
Method from org.springframework.core.io.ClassPathResource Summary:
createRelative,   equals,   getClassLoader,   getDescription,   getFile,   getFileForLastModifiedCheck,   getFilename,   getInputStream,   getPath,   getURL,   hashCode
Methods from org.springframework.core.io.AbstractResource:
createRelative,   equals,   exists,   getFile,   getFileForLastModifiedCheck,   getFilename,   getURI,   getURL,   hashCode,   isOpen,   isReadable,   lastModified,   toString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.core.io.ClassPathResource Detail:
 public Resource createRelative(String relativePath) 
    This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.
 public boolean equals(Object obj) 
    This implementation compares the underlying class path locations.
 public final ClassLoader getClassLoader() 
    Return the ClassLoader that this resource will be obtained from.
 public String getDescription() 
    This implementation returns a description that includes the class path location.
 public File getFile() throws IOException 
    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() throws IOException 
    This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).
 public String getFilename() 
    This implementation returns the name of the file that this class path resource refers to.
 public InputStream getInputStream() throws IOException 
    This implementation opens an InputStream for the given class path resource.
 public final String getPath() 
    Return the path for this resource (as resource path within the class path).
 public URL getURL() throws IOException 
    This implementation returns a URL for the underlying class path resource.
 public int hashCode() 
    This implementation returns the hash code of the underlying class path location.