Package org.unbescape

Class ClassLoaderUtils

java.lang.Object
org.unbescape.ClassLoaderUtils

final class ClassLoaderUtils extends Object

Utility class for obtaining a correct classloader on which to operate from a specific class.

Since:
1.1.6
  • Field Details

    • classClassLoader

      private static final ClassLoader classClassLoader
    • systemClassLoader

      private static final ClassLoader systemClassLoader
    • systemClassLoaderAccessibleFromClassClassLoader

      private static final boolean systemClassLoaderAccessibleFromClassClassLoader
  • Constructor Details

    • ClassLoaderUtils

      private ClassLoaderUtils()
  • Method Details

    • loadResourceAsStream

      static InputStream loadResourceAsStream(String resourceName) throws IOException

      Obtain a resource by name, throwing an exception if it is not present.

      First the context class loader will be used. If this class loader is not able to locate the resource, then the class class loader (ClassLoaderUtils.class.getClassLoader()) will be used if it is different from the thread context one. Last, the System class loader will be tried.

      This method does never return null.

      Parameters:
      resourceName - the name of the resource to be obtained.
      Returns:
      an input stream on the resource (null never returned).
      Throws:
      IOException - if the resource could not be located.
    • findResourceAsStream

      static InputStream findResourceAsStream(String resourceName)

      Try to obtain a resource by name, returning null if it could not be located.

      This method works very similarly to loadResourceAsStream(String) but will just return null if the resource cannot be located by the sequence of class loaders being tried.

      Parameters:
      resourceName - the name of the resource to be obtained.
      Returns:
      an input stream on the resource, or null if it could not be located.
    • getThreadContextClassLoader

      private static ClassLoader getThreadContextClassLoader()
    • getClassClassLoader

      private static ClassLoader getClassClassLoader(Class<?> clazz)
    • getSystemClassLoader

      private static ClassLoader getSystemClassLoader()
    • isKnownClassLoaderAccessibleFrom

      private static boolean isKnownClassLoaderAccessibleFrom(ClassLoader accessibleCL, ClassLoader fromCL)
    • isKnownLeafClassLoader

      private static boolean isKnownLeafClassLoader(ClassLoader classLoader)