org.springframework.core.io
Class ClassPathResource

public class ClassPathResource
extends AbstractResource
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.

Since28.12.2003
VersionNot specified.
AuthorJuergen Hoeller
Wiki javadoc Use textile entry format.
Add your comments here.
Constructor Summary
ClassPathResource( String path )
Create a new ClassPathResource for ClassLoader usage.
ClassPathResource( String path, ClassLoader classLoader )
Create a new ClassPathResource for ClassLoader usage.
ClassPathResource( String path, Class clazz )
Create a new ClassPathResource for Class usage.
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.
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.
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.
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 org.springframework.core.ioAbstractResource
Methods inherited from org.springframework.core.ioResource
ClassPathResource
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
TypeNameDescription
String path the absolute path within the class path
Wiki javadoc Use textile entry format.
Add your comments here.
ClassPathResource
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
TypeNameDescription
String path the absolute path within the classpath
ClassLoader classLoader the class loader to load the resource with, or null for the thread context class loader
Wiki javadoc Use textile entry format.
Add your comments here.
ClassPathResource
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
TypeNameDescription
String path relative or absolute path within the class path
Class clazz the class to load resources with
Wiki javadoc Use textile entry format.
Add your comments here.
ClassPathResource
protected ClassPathResource ( String path, ClassLoader classLoader, Class clazz )
Create a new ClassPathResource with optional ClassLoader and Class. Only for internal usage.
Parameters
TypeNameDescription
String path relative or absolute path within the classpath
ClassLoader classLoader the class loader to load the resource with, if any
Class clazz the class to load resources with, if any
Wiki javadoc Use textile entry format.
Add your comments here.
createRelative
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.
Overrides method in AbstractResource
Parameters
TypeNameDescription
String relativePath No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
equals
public boolean equals ( Object obj )
This implementation compares the underlying class path locations.
Overrides method in AbstractResource
Parameters
TypeNameDescription
Object obj No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
getDescription
public String getDescription ( )
This implementation returns a description that includes the class path location.
Overrides method in AbstractResource
Wiki javadoc Use textile entry format.
Add your comments here.
getFile
public File getFile ( )
throws
This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.
Overrides method in AbstractResource
Exceptions
IOException No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
getFilename
public String getFilename ( )
This implementation returns the name of the file that this class path resource refers to.
Overrides method in AbstractResource
Wiki javadoc Use textile entry format.
Add your comments here.
getInputStream
public InputStream getInputStream ( )
throws
This implementation opens an InputStream for the given class path resource.
Implements method in InputStreamSource
Exceptions
IOException No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
getPath
public String getPath ( )
Return the path for this resource.
Wiki javadoc Use textile entry format.
Add your comments here.
getURL
public URL getURL ( )
throws
This implementation returns a URL for the underlying class path resource.
Overrides method in AbstractResource
Exceptions
IOException No description provided.
Wiki javadoc Use textile entry format.
Add your comments here.
hashCode
public int hashCode ( )
This implementation returns the hash code of the underlying class path location.
Overrides method in AbstractResource
Wiki javadoc Use textile entry format.
Add your comments here.