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 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
long
|
contentLength()
This implementation checks the timestamp of the underlying File,
if available.
|
boolean
|
exists()
This implementation checks whether a File can be opened,
falling back to whether an InputStream can be opened.
|
File
|
getFile(URI uri)
This implementation returns a File reference for the underlying class path
resource, provided that it refers to a file in the file system.
|
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.
|
File
|
getFileForLastModifiedCheck()
This implementation determines the underlying File
(or jar file, in case of a resource in a jar/zip).
|
boolean
|
isReadable()
This implementation always returns true .
|
long
|
lastModified()
This implementation checks the timestamp of the underlying File,
if available.
|
|
From class
org.springframework.core.io.AbstractResource
long
|
contentLength()
This implementation checks the timestamp of the underlying File,
if available.
|
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.
|
boolean
|
exists()
This implementation checks whether a File can be opened,
falling back to whether an InputStream can be opened.
|
File
|
getFile()
This implementation throws a FileNotFoundException, assuming
that the resource cannot be resolved to an absolute file path.
|
File
|
getFileForLastModifiedCheck()
Determine the File to use for timestamp checking.
|
String
|
getFilename()
This implementation always throws IllegalStateException,
assuming that the resource does not have a filename.
|
URI
|
getURI()
This implementation builds a URI based on the URL returned
by getURL() .
|
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.
|
boolean
|
isOpen()
This implementation always returns false .
|
boolean
|
isReadable()
This implementation always returns true .
|
long
|
lastModified()
This implementation checks the timestamp of the underlying File,
if available.
|
String
|
toString()
This implementation returns the description of this resource.
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
From interface
org.springframework.core.io.InputStreamSource
|
From interface
org.springframework.core.io.Resource
abstract
long
|
contentLength()
Determine the content length for this resource.
|
abstract
Resource
|
createRelative(String relativePath)
Create a resource relative to this resource.
|
abstract
boolean
|
exists()
Return whether this resource actually exists in physical form.
|
abstract
String
|
getDescription()
Return a description for this resource,
to be used for error output when working with the resource.
|
abstract
File
|
getFile()
Return a File handle for this resource.
|
abstract
String
|
getFilename()
Return a filename for this resource, i.e.
|
abstract
URI
|
getURI()
Return a URI handle for this resource.
|
abstract
URL
|
getURL()
Return a URL handle for this resource.
|
abstract
boolean
|
isOpen()
Return whether this resource represents a handle with an open
stream.
|
abstract
boolean
|
isReadable()
Return whether the contents of this resource can be read,
e.g.
|
abstract
long
|
lastModified()
Determine the last-modified timestamp for this resource.
|
|
Public Constructors
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 |
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 |
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 |
Protected Constructors
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
|
Public Methods
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.
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
()
This implementation checks for the resolution of a resource URL.
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
String
getFilename
()
This implementation returns the name of the file that this class path
resource refers to.
public
InputStream
getInputStream
()
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
()
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.