/** Returns {@code findResources(cls, name, 1)[0]} or null if none. */ public static URL findResource(Class cls, String name) throws IOException { URL[] url = findResources(cls, name, 1); return url.length > 0 ? url[0] : null; }
/** Returns {@code findResources(cls, name, -1)}. */ public static URL[] findResources(Class cls, String name) throws IOException { return findResources(cls, name, -1); }
/** * Extracts by name resources using the {@link ClassLoader} of the specified {@link Class}. * * @param cls the Class from which to load resources * @param name of the resources passed to {@link #findResources(Class, String)} * @see #extractResource(URL, File, String, String) */ public static File[] extractResources(Class cls, String name, File directory, String prefix, String suffix) throws IOException { URL[] urls = findResources(cls, name); File[] files = new File[urls.length]; for (int i = 0; i < urls.length; i++) { files[i] = extractResource(urls[i], directory, prefix, suffix); } return files; }
/** * Extracts resources using the {@link ClassLoader} of the specified {@link Class}, * and returns the cached {@link File} objects. * * @param cls the Class from which to load resources * @param name of the resources passed to {@link #findResources(Class, String)} * @see #cacheResource(URL) */ public static File[] cacheResources(Class cls, String name) throws IOException { URL[] urls = findResources(cls, name); File[] files = new File[urls.length]; for (int i = 0; i < urls.length; i++) { files[i] = cacheResource(urls[i]); } return files; }