List of utility methods to do Resource Load
List | getFilesRecurse(File dir, final String pattern) get Files Recurse return getFilesRecurse(dir, pattern, null);
|
List | getFilesRecursevely(final String sourceFolder, final String classRegEx) get Files Recursevely return getFilesRecursevely(sourceFolder, classRegEx, true);
|
String | getResource(Class c, String name) get Resource InputStream is = c.getResourceAsStream(name); StringBuilder text = new StringBuilder(); Scanner scanner = new Scanner(is, "UTF-8"); try { while (scanner.hasNextLine()) { text.append(scanner.nextLine()); text.append("\n"); } finally { scanner.close(); return text.toString(); |
String | getResource(Class c, String name) Reads a string resource from the resource path (=classpath) of the given class. InputStream is = c.getResourceAsStream(name);
return getResource(is);
|
InputStream | getResource(Class c, String path) get Resource return c.getResourceAsStream(path);
|
String | getResource(Class clazz, String fileName) get Resource try { File file = new File(clazz.getResource(fileName).getFile()); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); StringBuilder builder = new StringBuilder(); String str; while ((str = in.readLine()) != null) { builder.append(str); in.close(); return builder.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); return null; |
String | getResource(Class clazz, String name, String charset) get Resource InputStream in = clazz.getResourceAsStream(name); try { return readerToString(new InputStreamReader(in, charset)); } finally { in.close(); |
InputStream | getResource(Class> c, String name) Similar to Class#getResourceAsStream(String) except looks up the parent hierarchy for the existence of the specified resource. if (name == null) return null; while (c != null) { InputStream is = c.getResourceAsStream(name); if (is != null) return is; c = c.getSuperclass(); return null; |
InputStream | getResource(ClassLoader classLoader, final String path) get Resource InputStream in = classLoader.getResourceAsStream(path); if (in == null) { throw new IOException("Empty resource."); return in; |
InputStream | getResource(final String aResName) Loads a resource from the classpath. return Thread.currentThread().getContextClassLoader().getResourceAsStream(aResName);
|