public class ClasspathResource extends Object implements Resource
Resource interface for handling Classpath resources. The classpath resources is responsible
for loading the resource from the user's classpath.The resource path is specified using the DataLoader's
filePaths attribute and can be prefixed with ResourceLoader.CLASSPATH_PREFIX in order for the
ResourceLoaderStrategy to pick them up. For eg. This class is automatically instantiated by the EasyTest's
ResourceLoaderStrategy when it sees the DataLoader annotation with the filePath attribute being
specified as: | Constructor and Description |
|---|
ClasspathResource(String path)
Construct a new ClasspathResource and defaults the
classLoader with current Threads ContextClassLoader |
ClasspathResource(String path,
Class<?> classObj)
Construct a new ClasspathResource instance such that the resource will be loaded using the given Class object.
|
ClasspathResource(String path,
ClassLoader classLoader)
Construct a new ClasspathResource instance such that the resource will be loaded using the given ClassLoader
|
ClasspathResource(String path,
ClassLoader classLoader,
Class<?> classObj) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
exists()
Identifies whether the resource exists or not.
|
ClassLoader |
getClassLoader() |
Class<?> |
getClassObj() |
File |
getFile()
Get the File associated with the given file path.
|
InputStream |
getInputStream()
Get the input stream associated with the given file path.
|
OutputStream |
getOutputStream()
Get the output Stream associated with the given resource.
|
String |
getPath() |
String |
getResourceName()
Get the resource Name associated with the given resource.
|
URL |
getURL()
Get the url associated with the given file path.
|
String |
toString() |
public ClasspathResource(String path)
classLoader with current Threads ContextClassLoaderpath - The path of the classpath resourceThread#currentThread()}'s getContextClassLoader method.public ClasspathResource(String path, ClassLoader classLoader)
path - the path of the classpath resourceclassLoader - The ClassLoader to load the class path resourcepublic ClasspathResource(String path, Class<?> classObj)
path - the path of the classpath resourceclassObj - The Class to load the class path resourcepublic ClasspathResource(String path, ClassLoader classLoader, Class<?> classObj)
public ClassLoader getClassLoader()
public String getPath()
public Class<?> getClassObj()
public boolean exists()
public InputStream getInputStream()
getInputStream in interface Resourcepublic URL getURL()
public File getFile()
public String getResourceName()
getResourceName in interface Resourcepublic OutputStream getOutputStream()
getOutputStream in interface ResourceCopyright © 2014. All rights reserved.