/** * Fetches and decodes the specified resource into a {@link BufferedImage}. * * @exception FileNotFoundException thrown if the resource could not be located in any of the * bundles in the specified set, or if the specified set does not exist. * @exception IOException thrown if a problem occurs locating or reading the resource. */ public BufferedImage getImageResource(String rset, String path) throws IOException { // grab the resource bundles in the specified resource set ResourceBundle[] bundles = getResourceSet(rset); if (bundles == null) { throw new FileNotFoundException( "Unable to locate image resource [set=" + rset + ", path=" + path + "]"); } String localePath = getLocalePath(path); // look for the resource in any of the bundles for (ResourceBundle bundle : bundles) { BufferedImage image; // try a localized version first if (localePath != null) { image = bundle.getImageResource(localePath, false); if (image != null) { return image; } } // if we didn't find that, try generic image = bundle.getImageResource(path, false); if (image != null) { return image; } } throw new FileNotFoundException( "Unable to locate image resource [set=" + rset + ", path=" + path + "]"); }
/** * Fetches and decodes the specified resource into a {@link BufferedImage}. * * @exception FileNotFoundException thrown if the resource could not be located in any of the * bundles in the specified set, or if the specified set does not exist. * @exception IOException thrown if a problem occurs locating or reading the resource. */ public BufferedImage getImageResource(String path) throws IOException { String localePath = getLocalePath(path); // first look for this resource in our default resource bundle for (ResourceBundle bundle : _default) { // try a localized version first BufferedImage image; if (localePath != null) { image = bundle.getImageResource(localePath, false); if (image != null) { return image; } } // if we didn't find that, try generic image = bundle.getImageResource(path, false); if (image != null) { return image; } } // fallback next to an unpacked resource file File file = getResourceFile(path); if (file != null && file.exists()) { return loadImage(file, path.endsWith(FastImageIO.FILE_SUFFIX)); } // if we still didn't find anything, try the classloader InputStream in; if (localePath != null) { in = getInputStreamFromClasspath(PathUtil.appendPath(_rootPath, localePath)); if (in != null) { return loadImage(in); } } in = getInputStreamFromClasspath(PathUtil.appendPath(_rootPath, path)); if (in != null) { return loadImage(in); } // if we still haven't found it, we throw an exception throw new FileNotFoundException("Unable to locate image resource [path=" + path + "]"); }