|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.mucommander.file.util.ResourceLoader
public class ResourceLoader
This class provides methods to load resources located within reach of a ClassLoader. Those resources
can reside either in a JAR file or in a local directory -- all methods of this class are agnostic to either type
of location.
The ResourceAsURL and ResourceAsStream methods are akin to those of java.lang.Class
and java.lang.ClassLoader, albeit easier to work with. But the real fun lies in the ResourceAsFile
methods which allow to manipulate resources as regular files -- again, whether they be in a regular directory or
in a JAR file. Finally, the getRootPackageAsFile(Class) method allows to list and manipulate the resource
files contained in a particular classpath's location, including the .class files.
| Constructor Summary | |
|---|---|
ResourceLoader()
|
|
| Method Summary | |
|---|---|
static java.lang.ClassLoader |
getDefaultClassLoader()
Returns the default ClassLoader that is used by methods without a ClassLoader argument. |
static AbstractFile |
getResourceAsFile(java.lang.String path)
Finds the resource with the given path and returns an AbstractFile that gives full access to it,
or null if the resource couldn't be located. |
static AbstractFile |
getResourceAsFile(java.lang.String path,
java.lang.ClassLoader classLoader)
Finds the resource with the given path and returns an AbstractFile that gives full access to it,
or null if the resource couldn't be located. |
static java.io.InputStream |
getResourceAsStream(java.lang.String path)
Finds the resource with the given path and returns an InputStream to read from it, or null
if the resource couldn't be located. |
static java.io.InputStream |
getResourceAsStream(java.lang.String path,
java.lang.ClassLoader classLoader)
Finds the resource with the given path and returns an InputStream to read from it, or null
The given ClassLoader is used for locating the resource. |
static java.net.URL |
getResourceAsURL(java.lang.String path)
Finds the resource with the given path and returns a URL pointing to its location, or null
if the resource couldn't be located. |
static java.net.URL |
getResourceAsURL(java.lang.String path,
java.lang.ClassLoader classLoader)
Finds the resource with the given path and returns a URL pointing to its location, or null
if the resource couldn't be located. |
static AbstractFile |
getRootPackageAsFile(java.lang.Class aClass)
Returns an AbstractFile to the root package of the given Class. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ResourceLoader()
| Method Detail |
|---|
public static java.lang.ClassLoader getDefaultClassLoader()
ClassLoader that is used by methods without a ClassLoader argument.
This default ClassLoader is the one that loaded this class, and not the system ClassLoader.
ClassLoader that is used by methods without a ClassLoader argumentpublic static java.net.URL getResourceAsURL(java.lang.String path)
null
if the resource couldn't be located.
The ClassLoader returned by getDefaultClassLoader() is used for locating the resource.
The given path may or may not start with a leading slash character ('/'), this doesn't affect the way it is interpreted.
path - a path to the resource, relative to the default ClassLoader's classpath
public static java.net.URL getResourceAsURL(java.lang.String path,
java.lang.ClassLoader classLoader)
null
if the resource couldn't be located.
The given ClassLoader is used for locating the resource. If it is null, the
ClassLoader returned by getDefaultClassLoader() is used.
The given path may or may not start with a leading slash character ('/'), this doesn't affect the way it is interpreted.
path - a path to the resource, relative to the given ClassLoader's classpathclassLoader - the ClassLoader used for locating the resource
public static java.io.InputStream getResourceAsStream(java.lang.String path)
InputStream to read from it, or null
if the resource couldn't be located.
The ClassLoader returned by getDefaultClassLoader() is used for locating the resource.
The given path may or may not start with a leading slash character ('/'), this doesn't affect the way it is interpreted.
path - a path to the resource, relative to the default ClassLoader's classpath
public static java.io.InputStream getResourceAsStream(java.lang.String path,
java.lang.ClassLoader classLoader)
InputStream to read from it, or null
The given ClassLoader is used for locating the resource. If it is null, the
ClassLoader returned by getDefaultClassLoader() is used.
The given path may or may not start with a leading slash character ('/'), this doesn't affect the way it is interpreted.
path - a path to the resource, relative to the given ClassLoader's classpathclassLoader - the Class whose ClassLoader is used for locating the resource
public static AbstractFile getResourceAsFile(java.lang.String path)
AbstractFile that gives full access to it,
or null if the resource couldn't be located.
The ClassLoader returned by getDefaultClassLoader() is used for locating the resource.
The given path may or may not start with a leading slash character ('/'), this doesn't affect the way it
is interpreted. Also noteworthy is this method may be slower than getResourceAsStream(String) if
the resource is located inside a JAR file, because the Zip file headers will have to be parsed the first time
the archive is accessed. So this latter method should be favored if the file is simply used for reading the
resource.
path - a path to the resource, relative to the default ClassLoader's classpath
public static AbstractFile getResourceAsFile(java.lang.String path,
java.lang.ClassLoader classLoader)
AbstractFile that gives full access to it,
or null if the resource couldn't be located.
The given ClassLoader is used for locating the resource. If it is null, the
ClassLoader returned by getDefaultClassLoader() is used.
The given path may or may not start with a leading slash character ('/'), this doesn't affect the way it
is interpreted. Also noteworthy is this method may be slower than getResourceAsStream(String) if
the resource is located inside a JAR file, because the Zip file headers will have to be parsed the first time
the archive is accessed. So this latter method should be favored if the file is simply used for reading the
resource.
path - a path to the resource, relative to the given ClassLoader's classpathclassLoader - the ClassLoader is used for locating the resource
public static AbstractFile getRootPackageAsFile(java.lang.Class aClass)
AbstractFile to the root package of the given Class. For example, if the
specified Class is java.lang.Object's, the returned file will be the Java runtime
JAR file, which on most platforms is $JAVA_HOME/lib/jre/rt.jar.
aClass - the class for which to locate the root package.
Class
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard