Class ClassUtils


  • public final class ClassUtils
    extends Object
    Provides class utility methods.
    • Method Detail

      • getContextClassLoader

        public static ClassLoader getContextClassLoader()
        Returns the context ClassLoader for this Thread.
        Returns:
        the context ClassLoader for this Thread, or null indicating the system class loader.
        See Also:
        Thread.getContextClassLoader()
      • setContextClassLoader

        public static ClassLoader setContextClassLoader​(ClassLoader classLoader)
        Override the context ClassLoader of this Thread.
        Parameters:
        classLoader - the ClassLoader to override.
        Returns:
        the previous context ClassLoader, or null if ClassLoader is not overriden.
      • getDefaultClassLoader

        public static ClassLoader getDefaultClassLoader()
        Returns the default ClassLoader.

        Generally, it is current Thread context ClassLoader. If not available, it will be the ClassLoader that loaded the ClassUtils.

        Returns:
        the default ClassLoader, or null if system ClassLoader is not accessible.
      • resourceToClassName

        public static String resourceToClassName​(String resource)
        Convert the '/' based resource path to '.' based class name.
        Parameters:
        resource - the resource path
        Returns:
        the corresponding fully qualified class name
      • classToResourceName

        public static String classToResourceName​(String klass)
        Convert the class name to '/' based resource path.
        Parameters:
        klass - the fully qualified class name
        Returns:
        the corresponding resource path
      • classToResourceName

        public static String classToResourceName​(Class<?> klass)
        Get the resource path of the given class.
        Parameters:
        klass - the class
        Returns:
        the corresponding resource path
      • isProxy

        public static boolean isProxy​(Object object)
        Check whether the given object is a CGLIB or ByteBuddy proxy.
        Parameters:
        object - the object to check
        Returns:
        true if object is proxy
      • isProxyClass

        public static boolean isProxyClass​(Class<?> clazz)
        Check whether the given class is a CGLIB or ByteBuddy proxy class, assuming no custom proxy class naming is used.
        Parameters:
        clazz - the class to check
        Returns:
        true of given class is a proxy class
      • isProxyClassName

        public static boolean isProxyClassName​(String className)
        Check whether the given class name is a CGLIB or ByteBuddy proxy class name, assuming no custom class naming is used.
        Parameters:
        className - the class name to check
        Returns:
        true if class name is proxy class name
      • getRealClass

        public static <T> Class<? super T> getRealClass​(Class<T> proxyClass)
        Get the real class of the given proxy class.
        Parameters:
        proxyClass - the proxy class whose first real super class is required.
        Returns:
        the real super class of the given proxy class, or itself if it's not a proxy class
      • getURL

        public static URL getURL​(String location)
                          throws FileNotFoundException
        Resolve the given resource location to a URL.
        Parameters:
        location - the resource location to resolve, either a pseudo 'classpath:' url, a 'file:' url or plain resource location.
        Returns:
        a corresponding URL object
        Throws:
        FileNotFoundException - if location can't be resolved.