Java Utililty Methods Resource Path Get

List of utility methods to do Resource Path Get

Description

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

Method

StringclassToResource(String className)
class To Resource
if (className == null)
    return null;
return className.replace('.', '/') + CLASS_FILE_NAME_EXTENSION;
Tdeserialize(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);
booleanexistsResource(String pathName)
exists Resource
URL url = ClassLoader.getSystemClassLoader().getResource(pathName);
return (url != null);
StringgetAbsolutePathFromResource(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());
...
URLgetAbsoluteResource(String path)
get Absolute Resource
return _getAbsoluteResource(path, true);
FilegetAlternateResourceFile(final String resourcePath)
get Alternate Resource File
return getResourceFileRelativeToBase(alternateResourceRootFolder, resourcePath);
StringgetBasePath(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);
ListgetChildResources(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")) {
...
URLgetClassResource(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)
...
ListgetClassResources(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();
...