public class

ClassPathResource

extends AbstractFileResolvingResource
java.lang.Object
   ↳ org.springframework.core.io.AbstractResource
     ↳ org.springframework.core.io.AbstractFileResolvingResource
       ↳ org.springframework.core.io.ClassPathResource

Class Overview

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.

Summary

Public Constructors
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.
Protected Constructors
ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz)
Create a new ClassPathResource with optional ClassLoader and Class.
Public Methods
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.
final 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.
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.
final 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.
[Expand]
Inherited Methods
From class org.springframework.core.io.AbstractFileResolvingResource
From class org.springframework.core.io.AbstractResource
From class java.lang.Object
From interface org.springframework.core.io.InputStreamSource
From interface org.springframework.core.io.Resource

Public Constructors

public ClassPathResource (String path)

Also: SpringCore

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

public ClassPathResource (String path, ClassLoader classLoader)

Also: SpringCore

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

public ClassPathResource (String path, Class<?> clazz)

Also: SpringCore

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

Protected Constructors

protected ClassPathResource (String path, ClassLoader classLoader, Class<?> clazz)

Also: SpringCore

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

Public Methods

public Resource createRelative (String relativePath)

Also: SpringCore

This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.

Parameters
relativePath the relative path (relative to this resource)
Returns
  • the resource handle for the relative resource

public boolean equals (Object obj)

This implementation compares the underlying class path locations.

public boolean exists ()

Also: SpringCore

This implementation checks for the resolution of a resource URL.

public final ClassLoader getClassLoader ()

Also: SpringCore

Return the ClassLoader that this resource will be obtained from.

public String getDescription ()

Also: SpringCore

This implementation returns a description that includes the class path location.

public String getFilename ()

Also: SpringCore

This implementation returns the name of the file that this class path resource refers to.

public InputStream getInputStream ()

Also: SpringCore

This implementation opens an InputStream for the given class path resource.

Throws
IOException

public final String getPath ()

Also: SpringCore

Return the path for this resource (as resource path within the class path).

public URL getURL ()

Also: SpringCore

This implementation returns a URL for the underlying class path resource.

Throws
IOException

public int hashCode ()

This implementation returns the hash code of the underlying class path location.