ResourceLoader { public static AbstractFile getRootPackageAsFile(Class<?> aClass) { ClassLoader classLoader = aClass.getClassLoader(); if(classLoader==null) classLoader = getDefaultClassLoader(); String aClassRelPath = getRelativeClassPath(aClass); URL aClassURL = getResourceAsURL(aClassRelPath, classLoader, null); if(aClassURL==null) return null; if("jar".equals(aClassURL.getProtocol())) return FileFactory.getFile(getJarFilePath(aClassURL)); String aClassPath = getLocalFilePath(aClassURL); return FileFactory.getFile(aClassPath.substring(0, aClassPath.length()-aClassRelPath.length())); }  static ClassLoader getDefaultClassLoader(); static void setDefaultClassLoader(ClassLoader defaultClassLoader); static URL getPackageResourceAsURL(Package ppackage, String name); static URL getPackageResourceAsURL(Package ppackage, String name, ClassLoader classLoader, AbstractFile rootPackageFile); static URL getResourceAsURL(String path); static URL getResourceAsURL(String path, ClassLoader classLoader, AbstractFile rootPackageFile); static InputStream getPackageResourceAsStream(Package ppackage, String name); static InputStream getPackageResourceAsStream(Package ppackage, String name, ClassLoader classLoader, AbstractFile rootPackageFile); static InputStream getResourceAsStream(String path); static InputStream getResourceAsStream(String path, ClassLoader classLoader, AbstractFile rootPackageFile); static AbstractFile getPackageResourceAsFile(Package ppackage, String name); static AbstractFile getPackageResourceAsFile(Package ppackage, String name, ClassLoader classLoader, AbstractFile rootPackageFile); static AbstractFile getResourceAsFile(String path); static AbstractFile getResourceAsFile(String path, ClassLoader classLoader, AbstractFile rootPackageFile); static AbstractFile getRootPackageAsFile(Class<?> aClass); static String getRelativePackagePath(Package ppackage); static String getRelativeClassPath(Class<?> cclass);  }
@Test public void testRootPackageAsFile() throws IOException { AbstractFile rootPackageFile = ResourceLoader.getRootPackageAsFile(getClass()); assert rootPackageFile != null; assert rootPackageFile.exists(); assert rootPackageFile.isBrowsable(); AbstractFile thisClassFile = rootPackageFile.getChild("com/mucommander/commons/file/util/ResourceLoaderTest.class"); assertReadable(thisClassFile); }