Class ResourceUtils
- java.lang.Object
-
- org.codehaus.cargo.util.log.LoggedObject
-
- org.codehaus.cargo.container.internal.util.ResourceUtils
-
- All Implemented Interfaces:
Loggable
public final class ResourceUtils extends LoggedObject
Utility class that provides a couple of methods for extracting files stored as resource in a JAR.
-
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copyResource(String resourceName, File destFile)
Copies a container resource from the JAR into the specified file.void
copyResource(String resourceName, File destFile, Map<String,String> replacements, Charset encoding)
Copies a container resource from the JAR into the specified file, thereby applying the specified filters.void
copyResource(String resourceName, String destFile, FileHandler handler)
Copies a container resource from the JAR into the specified file using the specified file handler.void
copyResource(String resourceName, String destFile, FileHandler handler, Map<String,String> replacements, Charset encoding)
Copies a container resource from the JAR into the specified file, using the specified file handler thereby applying the specified filters.static ClassLoader
getResourceLoader()
File
getResourceLocation(Class where, String resourceName)
Search for the given resource and return the directory or archive that contains it.String
readResource(String resourceName, Map<String,String> replacements, Charset encoding)
Reads a container resource from the JAR, applies the specified filters and returns content as String.void
setLogger(Logger logger)
Overriden in order to set the logger on ancillary components.static void
setResourceLoader(ClassLoader resourceLoader)
-
Methods inherited from class org.codehaus.cargo.util.log.LoggedObject
getLogger
-
-
-
-
Method Detail
-
getResourceLoader
public static ClassLoader getResourceLoader()
- Returns:
- Class loader used for the
getResourceAsStream
calls.
-
setResourceLoader
public static void setResourceLoader(ClassLoader resourceLoader)
- Parameters:
resourceLoader
- Class loader used for thegetResourceAsStream
calls.
-
setLogger
public void setLogger(Logger logger)
Overriden in order to set the logger on ancillary components.- Specified by:
setLogger
in interfaceLoggable
- Overrides:
setLogger
in classLoggedObject
- Parameters:
logger
- the logger to set and set in the ancillary objects
-
copyResource
public void copyResource(String resourceName, File destFile) throws IOException
Copies a container resource from the JAR into the specified file.- Parameters:
resourceName
- The name of the resourcedestFile
- The file to which the contents of the resource should be copied- Throws:
IOException
- If an I/O error occurs while copying the resource
-
copyResource
public void copyResource(String resourceName, String destFile, FileHandler handler) throws IOException
Copies a container resource from the JAR into the specified file using the specified file handler.- Parameters:
resourceName
- The name of the resourcedestFile
- The file to which the contents of the resource should be copiedhandler
- The file handler to use- Throws:
IOException
- If an I/O error occurs while copying the resource
-
copyResource
public void copyResource(String resourceName, File destFile, Map<String,String> replacements, Charset encoding) throws IOException
Copies a container resource from the JAR into the specified file, thereby applying the specified filters.- Parameters:
resourceName
- The name of the resource, relative to the org.codehaus.cargo.container.internal.util packagedestFile
- The file to which the contents of the resource should be copiedreplacements
- The ordered list of replacements that should be applied while copyingencoding
- The encoding that should be used when copying the resource. Use null for system default encoding- Throws:
IOException
- If an I/O error occurs while copying the resource
-
copyResource
public void copyResource(String resourceName, String destFile, FileHandler handler, Map<String,String> replacements, Charset encoding) throws IOException
Copies a container resource from the JAR into the specified file, using the specified file handler thereby applying the specified filters.- Parameters:
resourceName
- The name of the resource, relative to the org.codehaus.cargo.container.internal.util packagedestFile
- The file to which the contents of the resource should be copiedhandler
- The file handler to be used for file copyreplacements
- The ordered list of replacements that should be applied while copyingencoding
- The encoding that should be used when copying the resource. Use null for system default encoding- Throws:
IOException
- If an I/O error occurs while copying the resource
-
getResourceLocation
public File getResourceLocation(Class where, String resourceName)
Search for the given resource and return the directory or archive that contains it.- Parameters:
where
- Class where to look for the resource (its class loader and parent class loaders are used recursively for the lookup).resourceName
- The name of the resource- Returns:
- The directory or archive containing the specified resource
-
readResource
public String readResource(String resourceName, Map<String,String> replacements, Charset encoding) throws IOException
Reads a container resource from the JAR, applies the specified filters and returns content as String.- Parameters:
resourceName
- The name of the resource, relative to theorg.codehaus.cargo.container.internal.util
packagereplacements
- The ordered list of replacements that should be applied while readingencoding
- The encoding that should be used when reading the resource. Use null for system default encoding- Returns:
- Content of resource as String.
- Throws:
IOException
- If an I/O error occurs while reading the resource
-
-