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

EnumerationgetResources(String path, ClassLoader loader)
get Resources
if (loader == null) {
    return null;
Enumeration<URL> enm = loader.getResources(path);
if (enm.hasMoreElements()) {
    return enm;
return loader.getResources(togglePath(path));
...
ListgetResources(String resourcePath, Class caller)
get Resources
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (resourcePath.startsWith("/")) {
    resourcePath = resourcePath.substring(1);
if (classLoader != null) {
    return toList(classLoader.getResources(resourcePath));
classLoader = caller.getClassLoader();
...
InputStreamgetResourceStream(final String bundle, final String path)
Returns an InputStream for a given resource within a bundle.
String location = Platform.getBundle(bundle).getLocation();
try {
    if (location.toLowerCase().endsWith(".jar")) {
        final int pos = location.indexOf("file:");
        if (pos != -1) {
            location = location.substring(pos + 5);
            if (!location.startsWith("/")) {
                location = (Platform.getInstallLocation().getURL().toString() + location).substring(6);
...
InputStreamgetResourceStream(String path)
get Resource Stream
return getResourceStream(path, null);
StringgetStringFromResource(Class clazz, String path)
get String From Resource
if (clazz == null)
    throw new IllegalArgumentException("clazz is null.");
if (path == null)
    throw new IllegalArgumentException("path is null.");
StringWriter swOut = new StringWriter();
try {
    URL resource = clazz.getResource(path);
    if (resource == null)
...
URLgetSystemResource(String path)
Returns a URL from the path used to load classes.
return ClassLoader.getSystemResource(path);
FilegetSystemResource(String path)
get System Resource
try {
    URL url = classLoader.getResource(path);
    if (url != null) {
        return new File(url.toURI());
    } else {
        throw new FileNotFoundException(path);
} catch (URISyntaxException e) {
...
TloadResource(final Class bundleClazz, final Class resourceTypeclazz, final String pathToFile)
Loads a resource from any OSGi Bundle
final Bundle bundle = FrameworkUtil.getBundle(bundleClazz);
final URL url = bundle.getEntry(pathToFile);
final InputStream stream = new FileInputStream(url.getFile());
try {
    if (resourceTypeclazz.isInstance(InputStream.class)) {
        return resourceTypeclazz.cast(stream);
} catch (final Exception e) {
...
ListloadResources(ClassLoader loader, String path)
Utility to load the specified resources indicated by the path using the specified classloader
ClassLoader classLoader = loader;
ArrayList<URL> list = new ArrayList<>();
try {
    Enumeration<URL> resources = classLoader.getResources(path);
    while (resources.hasMoreElements()) {
        URL url = resources.nextElement();
        list.add(url);
} catch (IOException e) {
    e.printStackTrace();
return list;
booleanresourceExists(String path)
resource Exists
if (isRemote(path)) {
    try {
        URL url = createURL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        int code = conn.getResponseCode();
        return code >= 200 && code < 300;
    } catch (IOException e) {
        return false;
...