org.springframework.core.io
Class ClassPathResource

java.lang.Object
  extended by org.springframework.core.io.ClassPathResource

public class ClassPathResource
extends java.lang.Object

These classes are all extracted from the Spring Framework in order to remove the dependency on the Spring library.

Author:
mikenereson

Constructor Summary
  ClassPathResource(java.lang.String path)
          Create a new ClassPathResource for ClassLoader usage.
  ClassPathResource(java.lang.String path, java.lang.Class clazz)
          Create a new ClassPathResource for Class usage.
  ClassPathResource(java.lang.String path, java.lang.ClassLoader classLoader)
          Create a new ClassPathResource for ClassLoader usage.
protected ClassPathResource(java.lang.String path, java.lang.ClassLoader classLoader, java.lang.Class clazz)
          Create a new ClassPathResource with optional ClassLoader and Class.
 
Method Summary
 boolean equals(java.lang.Object object)
          This implementation compares the underlying class path locations.
 boolean exists()
          This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
 java.io.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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassPathResource

public ClassPathResource(java.lang.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
See Also:
ClassLoader.getResourceAsStream(String)

ClassPathResource

public ClassPathResource(java.lang.String path,
                         java.lang.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
See Also:
ClassLoader.getResourceAsStream(String)

ClassPathResource

public ClassPathResource(java.lang.String path,
                         java.lang.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
See Also:
Class.getResourceAsStream(java.lang.String)

ClassPathResource

protected ClassPathResource(java.lang.String path,
                            java.lang.ClassLoader classLoader,
                            java.lang.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 Detail

getFile

public java.io.File getFile()
                     throws java.io.IOException

This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.

Returns:
File
Throws:
java.io.IOException - when file not found

equals

public boolean equals(java.lang.Object object)

This implementation compares the underlying class path locations.

Overrides:
equals in class java.lang.Object

exists

public boolean exists()

This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.

Returns:
boolean


Copyright © 2007. All Rights Reserved.