org.arakhne.vmutil
Class Resources

java.lang.Object
  extended by org.arakhne.vmutil.Resources

public class Resources
extends Object

This utility class provides to load resources according to several heuristics:

Since:
4.2
Version:
7.2 (rev:394) 2013-03-20 23:37:56
Author:
Stéphane GALLAND
Maven Group Id:
org.arakhne.afc
Maven Artifact Id:
arakhneVmutils

Field Summary
static String NAME_SEPARATOR
          Character used to separate paths on an resource name.
 
Constructor Summary
Resources()
           
 
Method Summary
static URL getPropertyFile(Class<?> classname, Locale locale)
          Replies the URL of a property resource that is associated to the given class.
static URL getPropertyFile(ClassLoader classLoader, Class<?> classname, Locale locale)
          Replies the URL of a property resource that is associated to the given class.
static URL getResource(Class<?> classname, String path)
          Replies the URL of a resource.
static URL getResource(ClassLoader classLoader, Package packagename, String path)
          Replies the URL of a resource.
static URL getResource(ClassLoader classLoader, String path)
          Replies the URL of a resource.
static URL getResource(String path)
          Replies the URL of a resource.
static InputStream getResourceAsStream(Class<?> classname, String path)
          Replies the input stream of a resource.
static InputStream getResourceAsStream(ClassLoader classLoader, Package packagename, String path)
          Replies the input stream of a resource.
static InputStream getResourceAsStream(ClassLoader classLoader, String path)
          Replies the input stream of a resource.
static InputStream getResourceAsStream(String path)
          Replies the input stream of a resource.
static String translateResourceName(String resourceName)
          Translate the given resource name according to the current JVM standard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_SEPARATOR

public static final String NAME_SEPARATOR
Character used to separate paths on an resource name.

See Also:
Constant Field Values
Constructor Detail

Resources

public Resources()
Method Detail

getResource

public static URL getResource(String path)
Replies the URL of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames.

The class loader replied by ClassLoaderFinder is used. If it is null, the class loader of the Resources class is used.

Parameters:
path - is the absolute path of the resource.
Returns:
the url of the resource or null if the resource was not found in class paths.

getResource

public static URL getResource(ClassLoader classLoader,
                              Package packagename,
                              String path)
Replies the URL of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames.

The name of packagename is translated into a resource path (by replacing the dots by slashes) and the given path is append to. For example, the two following codes are equivalent:


 Resources.getResources(Package.getPackage("org.arakhne.afc"), "/a/b/c/d.png");
 Resources.getResources("org/arakhne/afc/a/b/c/d.png");
 

If the classLoader parameter is null, the class loader replied by ClassLoaderFinder is used. If this last is null, the class loader of the Resources class is used.

Parameters:
classLoader - is the research scope. If null, the class loader replied by ClassLoaderFinder is used.
packagename - is the package in which the resource should be located.
path - is the relative path of the resource in the package.
Returns:
the url of the resource or null if the resource was not found in class paths.
Since:
6.2

getResource

public static URL getResource(Class<?> classname,
                              String path)
Replies the URL of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames.

The name of classname is translated into a resource path (by remove the name of the class and replacing the dots by slashes) and the given path is append to. For example, the two following codes are equivalent:


 Resources.getResources(Resources.class, "/a/b/c/d.png");
 Resources.getResources("org/arakhne/vmutil/a/b/c/d.png");
 

The class loader of the given class is used. If it is null, the class loader replied by ClassLoaderFinder is used. If it is also null, the class loader of this Resources class is used.

Parameters:
classname - is located in the package in which the resource should be also located.
path - is the absolute path of the resource.
Returns:
the url of the resource or null if the resource was not found in class paths.

getResource

public static URL getResource(ClassLoader classLoader,
                              String path)
Replies the URL of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames.

If the classLoader parameter is null, the class loader replied by ClassLoaderFinder is used. If this last is null, the class loader of the Resources class is used.

Parameters:
classLoader - is the research scope. If null, the class loader replied by ClassLoaderFinder is used.
path - is the absolute path of the resource.
Returns:
the url of the resource or null if the resource was not found in class paths.

getResourceAsStream

public static InputStream getResourceAsStream(String path)
Replies the input stream of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames, and may not start the path with a slash.

The class loader replied by ClassLoaderFinder is used. If it is null, the class loader of the Resources class is used.

Parameters:
path - is the absolute path of the resource.
Returns:
the url of the resource or null if the resource was not found in class paths.

getResourceAsStream

public static InputStream getResourceAsStream(ClassLoader classLoader,
                                              Package packagename,
                                              String path)
Replies the input stream of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames.

The name of packagename is translated into a resource path (by replacing the dots by slashes) and the given path is append to. For example, the two following codes are equivalent:


 Resources.getResources(Package.getPackage("org.arakhne.afc"), "/a/b/c/d.png");
 Resources.getResources("org/arakhne/afc/a/b/c/d.png");
 

If the classLoader parameter is null, the class loader replied by ClassLoaderFinder is used. If this last is null, the class loader of the Resources class is used.

Parameters:
classLoader - is the research scope. If null, the class loader replied by ClassLoaderFinder is used.
packagename - is the package in which the resource should be located.
path - is the relative path of the resource in the package.
Returns:
the url of the resource or null if the resource was not found in class paths.
Since:
6.2

getResourceAsStream

public static InputStream getResourceAsStream(Class<?> classname,
                                              String path)
Replies the input stream of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames.

The name of classname is translated into a resource path (by remove the name of the class and replacing the dots by slashes) and the given path is append to. For example, the two following codes are equivalent:


 Resources.getResources(Resources.class, "/a/b/c/d.png");
 Resources.getResources("org/arakhne/vmutil/a/b/c/d.png");
 

The class loader of the given class is used. If it is null, the class loader replied by ClassLoaderFinder is used. If it is also null, the class loader of this Resources class is used.

Parameters:
classname - is located in the package in which the resource should be also located.
path - is the absolute path of the resource.
Returns:
the url of the resource or null if the resource was not found in class paths.

getResourceAsStream

public static InputStream getResourceAsStream(ClassLoader classLoader,
                                              String path)
Replies the input stream of a resource.

You may use Unix-like syntax to write the resource path, ie. you may use slashes to separate filenames, and may not start the path with a slash.

If the classLoader parameter is null, the class loader replied by ClassLoaderFinder is used. If this last is null, the class loader of the Resources class is used.

Parameters:
classLoader - is the research scope. If null, the class loader replied by ClassLoaderFinder is used.
path - is the absolute path of the resource.
Returns:
the url of the resource or null if the resource was not found in class paths.

getPropertyFile

public static URL getPropertyFile(Class<?> classname,
                                  Locale locale)
Replies the URL of a property resource that is associated to the given class.

Parameters:
classname - is the class for which the property resource should be replied.
locale - is the expected localization of the resource file; or null for the default.
Returns:
the url of the property resource or null if the resource was not found in class paths.
Since:
7.0

getPropertyFile

public static URL getPropertyFile(ClassLoader classLoader,
                                  Class<?> classname,
                                  Locale locale)
Replies the URL of a property resource that is associated to the given class.

Parameters:
classLoader - is the research scope. If null, the class loader replied by ClassLoaderFinder is used.
classname - is the class for which the property resource should be replied.
locale - is the expected localization of the resource file; or null for the default.
Returns:
the url of the property resource or null if the resource was not found in class paths.

translateResourceName

public static String translateResourceName(String resourceName)
Translate the given resource name according to the current JVM standard.

The resourceName argument should be a fully qualified class name. However, for compatibility with earlier versions, Sun's Java SE Runtime Environments do not verify this, and so it is possible to access PropertyResourceBundles by specifying a path name (using "/") instead of a fully qualified class name (using "."). In several VM, such as Dalvik, the translation from "." to "/" is not automatically done by the VM to retreive the file.

Parameters:
resourceName -
Returns:
the translated resource name.
Since:
7.0


Copyright © 2006-2013 Arakhnê.org Consortium. All rights reserved under LGPL license terms.