org.easetech.easytest.io
Class ClasspathResource

java.lang.Object
  extended by org.easetech.easytest.io.ClasspathResource
All Implemented Interfaces:
Resource

public class ClasspathResource
extends Object
implements Resource

An instance of 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:

Author:
Anuj Kumar

Constructor Summary
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)
           
 
Method Summary
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClasspathResource

public ClasspathResource(String path)
Construct a new ClasspathResource and defaults the classLoader with current Threads ContextClassLoader

Parameters:
path - The path of the classpath resource
See Also:
Thread#currentThread()}'s getContextClassLoader method.

ClasspathResource

public ClasspathResource(String path,
                         ClassLoader classLoader)
Construct a new ClasspathResource instance such that the resource will be loaded using the given ClassLoader

Parameters:
path - the path of the classpath resource
classLoader - The ClassLoader to load the class path resource

ClasspathResource

public ClasspathResource(String path,
                         Class<?> classObj)
Construct a new ClasspathResource instance such that the resource will be loaded using the given Class object.

Parameters:
path - the path of the classpath resource
classObj - The Class to load the class path resource

ClasspathResource

public ClasspathResource(String path,
                         ClassLoader classLoader,
                         Class<?> classObj)
Method Detail

getClassLoader

public ClassLoader getClassLoader()
Returns:
the classLoader

getPath

public String getPath()
Returns:
the path

getClassObj

public Class<?> getClassObj()
Returns:
the classObj

exists

public boolean exists()
Identifies whether the resource exists or not.

Specified by:
exists in interface Resource
Returns:
boolean indicating whether the resouorce exists or not

getInputStream

public InputStream getInputStream()
Get the input stream associated with the given file path.

Specified by:
getInputStream in interface Resource
Returns:
the input stream associated with the given file path.

getURL

public URL getURL()
Get the url associated with the given file path.

Specified by:
getURL in interface Resource
Returns:
the url associated with the given file path.

getFile

public File getFile()
Get the File associated with the given file path.

Specified by:
getFile in interface Resource
Returns:
the File associated with the given file path.

getResourceName

public String getResourceName()
Get the resource Name associated with the given resource.

Specified by:
getResourceName in interface Resource
Returns:
the resource name associated with the given resource.

getOutputStream

public OutputStream getOutputStream()
Get the output Stream associated with the given resource.

Specified by:
getOutputStream in interface Resource
Returns:
the output stream name associated with the given resource.

toString

public String toString()
Overrides:
toString in class Object
Returns:


Copyright © 2013. All Rights Reserved.