List of utility methods to do Resource Load
List | getResourceNames(String resName) get Resource Names return getResourceNames(resName, ""); |
List | getResourceNamesFromDir(File dir, String extension) get Resource Names From Dir List<String> testResources = new ArrayList<String>(); collectResourceNamesFromDir(dir, "", extension, testResources); return testResources; |
String | getResourcePath() get Resource Path return getHome() + File.separator + "resource\\"; |
String | getResourcePath(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(); |
Reader | getResourceReader(final String aResName) Loads a resource from the classpath. final InputStream resource = getResource(aResName); if (resource == null) { return null; return new InputStreamReader(resource); |
void | getResources(File root, File path, Vector 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") ... |
Collection | getResources(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; |
Collection | getResourceScripts(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; |
List | getResourcesFromDirectory(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); ... |
Collection | getResourcesFromDirectory(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(); ... |