/** * Returns an input stream from which the requested resource can be loaded. <em>Note:</em> this * performs a linear search of all of the bundles in the set and returns the first resource found * with the specified path, thus it is not extremely efficient and will behave unexpectedly if you * use the same paths in different resource bundles. * * @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 InputStream getResource(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 resource [set=" + rset + ", path=" + path + "]"); } String localePath = getLocalePath(path); // look for the resource in any of the bundles for (ResourceBundle bundle : bundles) { InputStream in; // Try a localized version first. if (localePath != null) { in = bundle.getResource(localePath); if (in != null) { return in; } } // If we didn't find that, try a generic. in = bundle.getResource(path); if (in != null) { return in; } } throw new FileNotFoundException( "Unable to locate resource [set=" + rset + ", path=" + path + "]"); }
/** * Fetches a resource from the local repository. * * @param path the path to the resource (ie. "config/miso.properties"). This should not begin with * a slash. * @exception IOException thrown if a problem occurs locating or reading the resource. */ public InputStream getResource(String path) throws IOException { String localePath = getLocalePath(path); InputStream in; // first look for this resource in our default resource bundle for (ResourceBundle bundle : _default) { // Try a localized version first. if (localePath != null) { in = bundle.getResource(localePath); if (in != null) { return in; } } // If that didn't work, try generic. in = bundle.getResource(path); if (in != null) { return in; } } // fallback next to an unpacked resource file File file = getResourceFile(path); if (file != null && file.exists()) { return new FileInputStream(file); } // if we still didn't find anything, try the classloader; first try a locale-specific file if (localePath != null) { in = getInputStreamFromClasspath(PathUtil.appendPath(_rootPath, localePath)); if (in != null) { return in; } } // if we didn't find that, try locale-neutral in = getInputStreamFromClasspath(PathUtil.appendPath(_rootPath, path)); if (in != null) { return in; } // if we still haven't found it, we throw an exception throw new FileNotFoundException("Unable to locate resource [path=" + path + "]"); }