org.jppf.classloader
Class ResourceProvider

java.lang.Object
  extended by org.jppf.classloader.ResourceProvider

public class ResourceProvider
extends Object

Instances of this class are dedicated to reading resource files form the JVM's classpath and converting them into arrays of bytes.

Author:
Laurent Cohen, Domingos Creado

Constructor Summary
ResourceProvider()
          Default constructor.
 
Method Summary
 byte[] computeCallable(byte[] serializedCallable)
          Compute a callable sent through the JPPF class loader.
 Map<String,List<byte[]>> getMultipleResourcesAsBytes(ClassLoader cl, String... names)
          Get all resources asssociated with each specified resource name.
 List<byte[]> getMultipleResourcesAsBytes(String name, ClassLoader cl)
          Get all resources asssociated with the specified resource name.
 byte[] getResource(String resName)
          Get a resource as an array of byte using a call to ClassLoader#getResource().
 byte[] getResource(String resName, ClassLoader cl)
          Get a resource as an array of byte using a call to ClassLoader#getResource().
 byte[] getResourceAsBytes(String resName)
          Load a resource file (including class files) from the class path into an array of byte.
 byte[] getResourceAsBytes(String resName, ClassLoader cl)
          Load a resource file (including class files) from the class path or the file system into an array of byte.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceProvider

public ResourceProvider()
Default constructor.

Method Detail

getResourceAsBytes

public byte[] getResourceAsBytes(String resName)
Load a resource file (including class files) from the class path into an array of byte.
This method simply calls getResourceAsBytes(String, ClassLoader) with a null class loader.

Parameters:
resName - the name of the resource to load.
Returns:
an array of bytes, or nll if the resource could not be found.

getResourceAsBytes

public byte[] getResourceAsBytes(String resName,
                                 ClassLoader cl)
Load a resource file (including class files) from the class path or the file system into an array of byte. The search order is defined as follows:
- first the search is performed in the order specified by ClassLoader.getResourceAsStream(String)
- if the resource is not found, it will be looked up in the file system

Parameters:
resName - the name of the resource to load.
cl - the class loader to use to load the request resource.
Returns:
an array of bytes, or nll if the resource could not be found.

getResource

public byte[] getResource(String resName)
Get a resource as an array of byte using a call to ClassLoader#getResource(). This method simply calls getResource(String, ClassLoader) with a null class loader.

Parameters:
resName - the name of the resource to find.
Returns:
the content of the resource as an array of bytes.

getResource

public byte[] getResource(String resName,
                          ClassLoader cl)
Get a resource as an array of byte using a call to ClassLoader#getResource().

Parameters:
resName - the name of the resource to find.
cl - the class loader to use to load the request resource.
Returns:
the content of the resource as an array of bytes.

computeCallable

public byte[] computeCallable(byte[] serializedCallable)
Compute a callable sent through the JPPF class loader.

Parameters:
serializedCallable - the callable to execute in serialized form.
Returns:
the serialized result of the callable's execution, or of an eventually resulting exception.

getMultipleResourcesAsBytes

public List<byte[]> getMultipleResourcesAsBytes(String name,
                                                ClassLoader cl)
Get all resources asssociated with the specified resource name.

Parameters:
name - the name of the resources to look for.
cl - the class loader used to load the resources.
Returns:
the content of all found resources as a list of byte arrays.

getMultipleResourcesAsBytes

public Map<String,List<byte[]>> getMultipleResourcesAsBytes(ClassLoader cl,
                                                            String... names)
Get all resources asssociated with each specified resource name.

Parameters:
cl - the class loader used to load the resources.
names - the names of all the resources to look for.
Returns:
A mapping of each resource names with a list of the byte content of corresponding resources in the classpath.


Copyright © 2005-2010 JPPF Team.