Java Resource Load getResourcesFromDirectory(final File directory, final Pattern pattern)

Here you can find the source of getResourcesFromDirectory(final File directory, final Pattern pattern)

Description

get Resources From Directory

License

Open Source License

Declaration

private static Collection<String> getResourcesFromDirectory(final File directory, final Pattern pattern) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;

import java.util.*;
import java.util.regex.Pattern;

public class Main {
    private static Collection<String> getResourcesFromDirectory(final File directory, final Pattern pattern) {
        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();
                    final boolean accept = pattern.matcher(fileName).matches();
                    if (accept) {
                        try {
                            retval.add(fileName.substring(0, fileName.lastIndexOf(File.separator)));
                        } catch (StringIndexOutOfBoundsException e1) {
                            //do nothing
                        }/*from  www .j  av  a2 s  . c o  m*/
                    }
                } catch (final IOException e) {
                    throw new Error(e);
                }
            }
        }
        return retval;
    }
}

Related

  1. getResourceReader(final String aResName)
  2. getResources(File root, File path, Vector result)
  3. getResources(final Pattern pattern)
  4. getResourceScripts(String path)
  5. getResourcesFromDirectory(File directory)
  6. getResourcesFromJarFile(File file, String resName)
  7. getResourcesFromJarFile(final File file, final Pattern pattern)
  8. getResourcesFromZip(final byte[] barContent)
  9. getResourceSize(ClassLoader classLoader, String path)