net.sourceforge.jaulp.io
Class ResourceUtils

java.lang.Object
  extended by net.sourceforge.jaulp.io.ResourceUtils

public class ResourceUtils
extends java.lang.Object

Utility class for the use Resource object.

Version:
1.0
Author:
Asterios Raptis

Constructor Summary
ResourceUtils()
           
 
Method Summary
static java.lang.ClassLoader getClassLoader(java.lang.Object obj)
          Gets the ClassLoader from the given object.
static java.lang.String getClassnameWithSuffix(java.lang.Object obj)
          Gets the classname and concats the suffix ".class" from the object.
static java.lang.String getPackagePath(java.lang.Object object)
          Determines the package path from the given object.
static java.lang.String getPackagePathWithSlash(java.lang.Object object)
          Determines the package path from the given object and adds a slash at the front.
static java.lang.String getPathFromObject(java.lang.Object obj)
          Finds the absolute path from the object.
static java.net.URL getResource(java.lang.String name)
          Gives the URL from the resource.
static
<T> java.net.URL
getResource(java.lang.String name, T obj)
          Gives the URL from the resource.
static java.io.File getResourceAsFile(java.lang.String name, java.lang.Object obj)
          Gives the resource as a file.
static java.io.InputStream getResourceAsStream(java.lang.String name)
          Gives the Inputstream from the resource.
static java.io.InputStream getResourceAsStream(java.lang.String name, java.lang.Object obj)
          Gives the Inputstream from the resource.
static java.net.URL getRessource(java.lang.Class clazz, java.lang.String path)
          Gives the url from the path back.
static java.io.InputStream getRessourceAsStream(java.lang.Class<?> clazz, java.lang.String uri)
          This method call the getResourceAsStream from the ClassLoader.
static boolean isDerivate(java.lang.ClassLoader source, java.lang.ClassLoader compare)
          Compares the two given ClassLoader objects and returns true if compare is a derivate of source.
static java.util.Properties loadProperties(java.lang.String packagePath)
          Gives a Properties-object from the given packagepath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceUtils

public ResourceUtils()
Method Detail

getClassnameWithSuffix

public static java.lang.String getClassnameWithSuffix(java.lang.Object obj)
Gets the classname and concats the suffix ".class" from the object.

Parameters:
obj - The object.
Returns:
The classname and concats the suffix ".class".

getPackagePath

public static java.lang.String getPackagePath(java.lang.Object object)
Determines the package path from the given object.

Parameters:
object - The object.
Returns:
The packae path from the given object.

getPackagePathWithSlash

public static java.lang.String getPackagePathWithSlash(java.lang.Object object)
Determines the package path from the given object and adds a slash at the front.

Parameters:
object - The object.
Returns:
The packae path from the given object with the added slash at the front.

getPathFromObject

public static java.lang.String getPathFromObject(java.lang.Object obj)
Finds the absolute path from the object.

Parameters:
obj - The object.
Returns:
The absolute path from the object.

getResource

public static java.net.URL getResource(java.lang.String name)
Gives the URL from the resource. Wrapes the Class.getResource(String)-method.

Parameters:
name - The name from the resource.
Returns:
The resource or null if the resource does not exists.

getResource

public static <T> java.net.URL getResource(java.lang.String name,
                                           T obj)
Gives the URL from the resource. Wrapes the Class.getResource(String)-method.

Parameters:
name - The name from the resource.
obj - The Object.
Returns:
The resource or null if the resource does not exists.

getResourceAsFile

public static java.io.File getResourceAsFile(java.lang.String name,
                                             java.lang.Object obj)
Gives the resource as a file.

Parameters:
name - The name from the file.
obj - The Object.
Returns:
The file or null if the file does not exists.

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String name)
Gives the Inputstream from the resource. Wrapes the Class.getResourceAsStream(String)-method.

Parameters:
name - The name from the resource.
Returns:
The resource or null if the resource does not exists.

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String name,
                                                      java.lang.Object obj)
Gives the Inputstream from the resource. Wrapes the Class.getResourceAsStream(String)-method.

Parameters:
name - The name from the resource.
obj - The Object.
Returns:
The resource or null if the resource does not exists.

getClassLoader

public static java.lang.ClassLoader getClassLoader(java.lang.Object obj)
Gets the ClassLoader from the given object.

Parameters:
obj - The object.
Returns:
the ClassLoader from the given object.

isDerivate

public static boolean isDerivate(java.lang.ClassLoader source,
                                 java.lang.ClassLoader compare)
Compares the two given ClassLoader objects and returns true if compare is a derivate of source.

Parameters:
source - the source
compare - the compare
Returns:
true, if compare is a derivate of source.

getRessource

public static java.net.URL getRessource(java.lang.Class clazz,
                                        java.lang.String path)
Gives the url from the path back.

Parameters:
clazz - The class-object.
path - The path.
Returns:
's the url from the path.

getRessourceAsStream

public static java.io.InputStream getRessourceAsStream(java.lang.Class<?> clazz,
                                                       java.lang.String uri)
This method call the getResourceAsStream from the ClassLoader. You can use this method to read files from jar-files.

Parameters:
uri - The uri as String.
Returns:
The InputStream from the uri.

loadProperties

public static java.util.Properties loadProperties(java.lang.String packagePath)
Gives a Properties-object from the given packagepath.

Parameters:
packagePath - The package-path and the name from the resource as a String.
Returns:
The Properties-object from the given packagepath.


Copyright © 2010. All Rights Reserved.