The list of methods to do Resource Path Get are organized into topic(s).
T
deserialize(Class> parentOfResource, String resourcePath, Class targetClass) deserialize
URL resourceUrl = parentOfResource.getResource(resourcePath);
requireNonNull(resourceUrl,
format("resource '%s' of class '%s' not found", resourcePath, parentOfResource.getCanonicalName()));
try {
return objectMapper.readValue(resourceUrl, targetClass);
} catch (IOException e) {
throw new RuntimeException(e);
String
getAbsolutePathFromResource(Class reference, String resource) Returns the absolute path of the resource.
URL urlResource = reference.getResource(resource);
if (urlResource == null)
return null;
String urlString = URLDecoder.decode(urlResource.toString());
if (urlString.startsWith("jar:"))
urlString = urlString.substring("jar:".length());
if (urlString.startsWith("file:"))
urlString = urlString.substring("file:".length());
...
String
getBasePath(Class clazz, String resource) Get the path to the directory containing the resource (including the trailing slash).
final String filename = getFilename(clazz, resource);
return getBasePath(filename);
List
getChildResources(String path)
get Child Resources
List<URL> result = new LinkedList<URL>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> p = classLoader.getResources(path);
while (p.hasMoreElements()) {
URL resource = p.nextElement();
if (resource.getProtocol().equalsIgnoreCase("FILE")) {
result.addAll(loadDirectory(resource.getFile()));
} else if (resource.getProtocol().equalsIgnoreCase("JAR")) {
...
URL
getClassResource(Class> clazz, String resPath) get Class Resource
URL url = clazz.getResource(resPath);
if (url == null) {
ClassLoader loader = clazz.getClassLoader();
if (loader != null)
url = loader.getResource(resPath);
if (url == null) {
loader = Thread.currentThread().getContextClassLoader();
if (loader != null)
...
List
getClassResources(Class> clazz, String resPath)
get Class Resources
List<URL> urlList = new ArrayList<URL>();
Enumeration<URL> urls = null;
try {
ClassLoader loader = clazz.getClassLoader();
if (loader != null)
urls = loader.getResources(resPath);
if (urls == null || !urls.hasMoreElements()) {
loader = Thread.currentThread().getContextClassLoader();
...