Java Utililty Methods Resource Load

List of utility methods to do Resource Load

Description

The list of methods to do Resource Load are organized into topic(s).

Method

ListgetResourceNames(String resName)
get Resource Names
return getResourceNames(resName, "");
ListgetResourceNamesFromDir(File dir, String extension)
get Resource Names From Dir
List<String> testResources = new ArrayList<String>();
collectResourceNamesFromDir(dir, "", extension, testResources);
return testResources;
StringgetResourcePath()
get Resource Path
return getHome() + File.separator + "resource\\";
StringgetResourcePath(Class c, String name)
Get resource in test scope for some class.
return new StringBuilder().append(baseResourcePath)
        .append(c.getPackage().getName().replace('.', File.separatorChar)).append(File.separator)
        .append(name).toString();
ReadergetResourceReader(final String aResName)
Loads a resource from the classpath.
final InputStream resource = getResource(aResName);
if (resource == null) {
    return null;
return new InputStreamReader(resource);
voidgetResources(File root, File path, Vector result)
get Resources
if (path == null)
    path = root;
File[] files = path.listFiles(new FileFilter() {
    public boolean accept(File pathname) {
        return pathname.isDirectory() || pathname.toString().toLowerCase().endsWith(".xml")
                || pathname.toString().toLowerCase().endsWith(".props")
                || pathname.toString().toLowerCase().endsWith(".properties")
                || pathname.toString().toLowerCase().endsWith(".r")
...
CollectiongetResources(final Pattern pattern)
for all elements of java.class.path get a Collection of resources Pattern pattern = Pattern.compile(".*"); gets all resources
final ArrayList<String> retval = new ArrayList<String>();
final String classPath = System.getProperty("java.class.path", ".");
final String[] classPathElements = classPath.split(System.getProperty("path.separator"));
for (final String element : classPathElements) {
    retval.addAll(getResources(element, pattern));
return retval;
CollectiongetResourceScripts(String path)
Gets the resource scripts.
System.out.println("getting files from " + path);
List<String> strFiles = new ArrayList<String>();
String file = null;
if (new File("stats-gen.jar").exists()) {
    file = "stats-gen.jar";
} else {
    file = "target/stats-gen.jar";
ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
while (true) {
    ZipEntry e = zip.getNextEntry();
    if (e == null)
        break;
    String name = e.getName();
    if (name.startsWith(path) && !name.endsWith("/")) {
        strFiles.add(name);
System.out.println("files:" + strFiles.toString());
return strFiles;
ListgetResourcesFromDirectory(File directory)
get Resources From Directory
List<String> retval = new ArrayList<String>();
File[] fileList = directory.listFiles();
for (File file : fileList) {
    if (file.isDirectory()) {
        retval.addAll(getResourcesFromDirectory(file));
    } else {
        String fileName = file.getName();
        retval.add(fileName);
...
CollectiongetResourcesFromDirectory(final File directory, final Pattern pattern)
get Resources From Directory
final Set<String> retval = new HashSet<String>();
final File[] fileList = directory.listFiles();
for (final File file : fileList) {
    if (file.isDirectory()) {
        retval.addAll(getResourcesFromDirectory(file, pattern));
    } else {
        try {
            final String fileName = file.getCanonicalPath();
...