/** * Resolves class file name from class name by replacing dot's with '/' separator * and adding class extension at the end. If array, component type is returned. */ public static String getClassFileName(Class clazz) { if (clazz.isArray()) { clazz = clazz.getComponentType(); } return getClassFileName(clazz.getName()); }
/** * Opens a class of the specified name for reading. No specific classloader is used * for loading class. * @see #getResourceAsStream(String, ClassLoader) */ public static InputStream getClassAsStream(String className) throws IOException { return getResourceAsStream(getClassFileName(className)); }
/** * Opens a class of the specified name for reading using class classloader. * @see #getResourceAsStream(String, ClassLoader) */ public static InputStream getClassAsStream(Class clazz) throws IOException { return getResourceAsStream(getClassFileName(clazz), clazz.getClassLoader()); }
/** * Opens a class of the specified name for reading using provided class loader. */ public static InputStream getClassAsStream(String className, ClassLoader classLoader) throws IOException { return getResourceAsStream(getClassFileName(className), classLoader); }