/** * This method is similar to {@link #getResourceAsStream(String, ClassLoader, AbstractFile)} except that it looks * for a resource with a given name in a specific package. * * @param ppackage package serving as a base folder for the resource to retrieve * @param name name of the resource in the package. This is a filename only, not a path. * @param classLoader the ClassLoader used for locating the resource. May not be <code>null</code>. * @param rootPackageFile root package location (JAR file or directory) that limits the scope of the search, * <code>null</code> to look for the resource in the whole class path. * @return an InputStream that allows to read the resource, or <code>null</code> if the resource couldn't be located */ public static InputStream getPackageResourceAsStream(Package ppackage, String name, ClassLoader classLoader, AbstractFile rootPackageFile) { return ResourceLoader.getResourceAsStream(getRelativePackagePath(ppackage)+"/"+name, classLoader, rootPackageFile); }
/** * This method is similar to {@link #getResourceAsURL(String)} except that it looks for a resource with a given * name in a specific package. * * @param ppackage package serving as a base folder for the resource to retrieve * @param classLoader the ClassLoader used for locating the resource. May not be <code>null</code>. * @param rootPackageFile root package location (JAR file or directory) that limits the scope of the search, * <code>null</code> to look for the resource in the whole class path. * @param name name of the resource in the package. This is a filename only, not a path. * @return a URL pointing to the resource, or <code>null</code> if the resource couldn't be located * @see #getRootPackageAsFile(Class) */ public static URL getPackageResourceAsURL(Package ppackage, String name, ClassLoader classLoader, AbstractFile rootPackageFile) { return ResourceLoader.getResourceAsURL(getRelativePackagePath(ppackage)+"/"+name, classLoader, rootPackageFile); }
/** * This method is similar to {@link #getResourceAsFile(String, ClassLoader, AbstractFile)} except that it looks for * a resource with a given name in a specific package. * * @param ppackage package serving as a base folder for the resource to retrieve * @param name name of the resource in the package. This is a filename only, not a path. * @param classLoader the ClassLoader used for locating the resource. May not be <code>null</code>. * @param rootPackageFile root package location (JAR file or directory) that limits the scope of the search, * <code>null</code> to look for the resource in the whole class path. * @return an AbstractFile that represents the resource, or <code>null</code> if the resource couldn't be located */ public static AbstractFile getPackageResourceAsFile(Package ppackage, String name, ClassLoader classLoader, AbstractFile rootPackageFile) { return ResourceLoader.getResourceAsFile(getRelativePackagePath(ppackage)+"/"+name, classLoader, rootPackageFile); }
/** * Tests {@link ResourceLoader#getRelativePackagePath(Package)}. */ @Test public void testRelativePackagePath() { // Returned path does not end with a '/' assert "com/mucommander/commons/file/util".equals(ResourceLoader.getRelativePackagePath(getThisPackage())); }