|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.xerial.util.FileResource
public class FileResource
Gets file URLs by using the ClassLoader facility. This utility can be
used to hold file resources within a package.
Usage:
// if YourClass belongs to a package org.xerial.util, the following code searches org/xerial/util/sample.txt in the source folder (or jar file)
URL fileResourceURL = FileResource.find(YourClass.class, "sample.txt");
// another form of the previous line
URL fileResourceURL2 = FileResource.find("org.xerial.util", "sample.txt");
// short-hand code to get Reader (equivalent to call new BufferedReader(new InputStreamReader(URL#openStream())) )
BufferedReader reader = FileResource.open(YourClass.class, "sample.txt");
| Nested Class Summary | |
|---|---|
static class |
FileResource.FileInJarArchive
A virtual file implementation for file resources contained in a JAR file |
static class |
FileResource.SystemFile
A virtual file implementation for usual files |
| Constructor Summary | |
|---|---|
FileResource()
|
|
| Method Summary | |
|---|---|
static URL |
find(Class referenceClass,
String resourceFileName)
Gets the URL of the file resource |
static URL |
find(Package basePackage,
String resourceFileName)
Finds the URL of the resource |
static URL |
find(String resourceFileName)
Finds the URL of the resource |
static URL |
find(String packageName,
String resourceFileName)
Finds the URL of the resource |
static URL |
findFromJAR(String jarPath,
String filePath)
|
static ArrayList<URLClassLoader> |
getAllAncestorOrSelfClassLoaders(ClassLoader classLoader)
Retrieves all URLClassLoaders that can be found from this class |
static List<VirtualFile> |
listResources(ClassLoader classLoader,
ResourceFilter resourceFilter)
Lists up all resources satisfying the given resourceFilter from the given current class loader |
static List<VirtualFile> |
listResources(ClassLoader classLoader,
String basePackageName,
ResourceFilter resourceFilter)
list up resources recursively under the given base package name |
static List<VirtualFile> |
listResources(ResourceFilter resourceFilter)
Lists up all resources satisfying the given resourceFilter from the current class loader |
static List<VirtualFile> |
listResources(String basePackageName)
list up resources recursively under the given base package name |
static List<VirtualFile> |
listResources(String basePackageName,
ResourceFilter resourceFilter)
list up resources recursively under the given base package name |
static List<VirtualFile> |
listResources(URL resourceURL,
String packagePath,
ResourceFilter resourceFilter)
Lists up all resources recursively under the given resourceURL. |
static BufferedReader |
open(Class referenceClass,
String resouceFileName)
Opens a stream to a file resource that belongs to the same package to the specified referenceClass |
static BufferedReader |
open(Package basePackage,
String resourceFileName)
Opens a stream to a file resource that belongs to the specified package |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileResource()
| Method Detail |
|---|
public static List<VirtualFile> listResources(String basePackageName)
basePackageName - package name to search. e.g. org.xerial.util
VirtualFilepublic static List<VirtualFile> listResources(ResourceFilter resourceFilter)
resourceFilter -
public static List<VirtualFile> listResources(ClassLoader classLoader,
ResourceFilter resourceFilter)
resourceFilter - classLoader -
public static List<VirtualFile> listResources(URL resourceURL,
String packagePath,
ResourceFilter resourceFilter)
resourceURL - resourceFilter -
public static List<VirtualFile> listResources(String basePackageName,
ResourceFilter resourceFilter)
basePackageName - package name to search. e.g. org.xerial.util
VirtualFile
public static List<VirtualFile> listResources(ClassLoader classLoader,
String basePackageName,
ResourceFilter resourceFilter)
classLoader - basePackageName - package name to search. e.g. org.xerial.util
VirtualFilepublic static ArrayList<URLClassLoader> getAllAncestorOrSelfClassLoaders(ClassLoader classLoader)
URLClassLoaders that can be found from this class
URLClassLoaders
public static BufferedReader open(Class referenceClass,
String resouceFileName)
throws IOException
referenceClass - the reference classresouceFileName - the file name of the resource, relative to the package of the
referenceClass
BufferedReader of the resource
IOException - when failed to open the file resource
public static BufferedReader open(Package basePackage,
String resourceFileName)
throws IOException
basePackage - the base package to load resourcesresouceFileName - the file name of the resource, relative to the package
BufferedReader of the resource
IOException - when failed to open the file resource
public static URL find(Class referenceClass,
String resourceFileName)
URL of the file resource
referenceClass - the base class to find resourcesresourceFileName - the resource file name relative to the package of the
referenceClass
public static URL find(Package basePackage,
String resourceFileName)
URL of the resource
basePackage - the base package to find the resourceresourceFileName - the resource file name relative to the package folder
public static URL find(String packageName,
String resourceFileName)
URL of the resource
packageName - the base package name to find the resourceresourceFileName - the resource file name relative to the package folder
public static URL findFromJAR(String jarPath,
String filePath)
public static URL find(String resourceFileName)
URL of the resource
resourceFileName - the resource file name, relative to the root package
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
