Added getResource() which searches the bundles in a resource set for the
resources. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1965 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: ResourceManager.java,v 1.17 2002/10/25 17:21:00 mdb Exp $
|
||||
// $Id: ResourceManager.java,v 1.18 2002/11/20 02:00:36 mdb Exp $
|
||||
|
||||
package com.threerings.resource;
|
||||
|
||||
@@ -486,6 +486,47 @@ public class ResourceManager
|
||||
throw new FileNotFoundException(errmsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 + "]");
|
||||
}
|
||||
|
||||
// look for the resource in any of the bundles
|
||||
int size = bundles.length;
|
||||
for (int ii = 0; ii < size; ii++) {
|
||||
InputStream instr = bundles[ii].getResource(path);
|
||||
if (instr != null) {
|
||||
// Log.info("Found resource [rset=" + rset +
|
||||
// ", bundle=" + bundles[ii].getSource().getPath() +
|
||||
// ", path=" + path + "].");
|
||||
return instr;
|
||||
}
|
||||
}
|
||||
|
||||
throw new FileNotFoundException(
|
||||
"Unable to locate resource [set=" + rset + ", path=" + path + "]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the resource set with the specified name, or
|
||||
* null if no set exists with that name. Services that wish to load
|
||||
|
||||
Reference in New Issue
Block a user