org.seventytwomiles.springframework.core.io
Class ClassPathResource

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

public class ClassPathResource
extends 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(String path)
          Create a new ClassPathResource for ClassLoader usage.
  ClassPathResource(String path, Class clazz)
          Create a new ClassPathResource for Class usage.
  ClassPathResource(String path, ClassLoader classLoader)
          Create a new ClassPathResource for ClassLoader usage.
protected ClassPathResource(String path, ClassLoader classLoader, Class clazz)
          Create a new ClassPathResource with optional ClassLoader and Class.
 
Method Summary
 boolean equals(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.
 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(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(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
See Also:
ClassLoader.getResourceAsStream(String)

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:
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(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 Detail

getFile

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.

Returns:
File
Throws:
IOException - when file not found

equals

public boolean equals(Object object)

This implementation compares the underlying class path locations.

Overrides:
equals in class 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-2008. All Rights Reserved.