Split getting an input stream from the classpath out for subclass customization
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@846 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -534,32 +534,21 @@ public class ResourceManager
|
|||||||
|
|
||||||
// if we still didn't find anything, try the classloader; first try a locale-specific file
|
// if we still didn't find anything, try the classloader; first try a locale-specific file
|
||||||
if (_localePrefix != null) {
|
if (_localePrefix != null) {
|
||||||
final String rpath = PathUtil.appendPath(
|
String rpath = PathUtil.appendPath(_rootPath, PathUtil.appendPath(_localePrefix, path));
|
||||||
_rootPath, PathUtil.appendPath(_localePrefix, path));
|
in = getInputStreamFromClasspath(rpath);
|
||||||
in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
|
||||||
public InputStream run () {
|
|
||||||
return _loader.getResourceAsStream(rpath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we didn't find that, try locale-neutral
|
// if we didn't find that, try locale-neutral
|
||||||
final String rpath = PathUtil.appendPath(_rootPath, path);
|
in = getInputStreamFromClasspath(PathUtil.appendPath(_rootPath, path));
|
||||||
in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
|
||||||
public InputStream run () {
|
|
||||||
return _loader.getResourceAsStream(rpath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we still haven't found it, we throw an exception
|
// if we still haven't found it, we throw an exception
|
||||||
String errmsg = "Unable to locate resource [path=" + path + "]";
|
throw new FileNotFoundException("Unable to locate resource [path=" + path + "]");
|
||||||
throw new FileNotFoundException(errmsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -577,8 +566,7 @@ public class ResourceManager
|
|||||||
// try a localized version first
|
// try a localized version first
|
||||||
BufferedImage image = null;
|
BufferedImage image = null;
|
||||||
if (_localePrefix != null) {
|
if (_localePrefix != null) {
|
||||||
image =
|
image = bundle.getImageResource(PathUtil.appendPath(_localePrefix, path), false);
|
||||||
bundle.getImageResource(PathUtil.appendPath(_localePrefix, path), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we didn't find that, try generic
|
// if we didn't find that, try generic
|
||||||
@@ -599,32 +587,21 @@ public class ResourceManager
|
|||||||
|
|
||||||
// first try a locale-specific file
|
// first try a locale-specific file
|
||||||
if (_localePrefix != null) {
|
if (_localePrefix != null) {
|
||||||
final String rpath = PathUtil.appendPath(
|
String rpath = PathUtil.appendPath(_rootPath, PathUtil.appendPath(_localePrefix, path));
|
||||||
_rootPath, PathUtil.appendPath(_localePrefix, path));
|
InputStream in = getInputStreamFromClasspath(rpath);
|
||||||
InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
|
||||||
public InputStream run () {
|
|
||||||
return _loader.getResourceAsStream(rpath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
return loadImage(in);
|
return loadImage(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we still didn't find anything, try the classloader
|
// if we still didn't find anything, try the classloader
|
||||||
final String rpath = PathUtil.appendPath(_rootPath, path);
|
InputStream in = getInputStreamFromClasspath(PathUtil.appendPath(_rootPath, path));
|
||||||
InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
|
||||||
public InputStream run () {
|
|
||||||
return _loader.getResourceAsStream(rpath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
return loadImage(in);
|
return loadImage(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we still haven't found it, we throw an exception
|
// if we still haven't found it, we throw an exception
|
||||||
String errmsg = "Unable to locate image resource [path=" + path + "]";
|
throw new FileNotFoundException("Unable to locate image resource [path=" + path + "]");
|
||||||
throw new FileNotFoundException(errmsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -874,6 +851,18 @@ public class ResourceManager
|
|||||||
return ImageIO.read(file);
|
return ImageIO.read(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an InputStream from this manager's classloader for the given path.
|
||||||
|
*/
|
||||||
|
protected InputStream getInputStreamFromClasspath (final String fullyQualifiedPath)
|
||||||
|
{
|
||||||
|
return AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
|
||||||
|
public InputStream run () {
|
||||||
|
return _loader.getResourceAsStream(fullyQualifiedPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an image from the given input stream. Supports formats supported by {@link ImageIO}
|
* Loads an image from the given input stream. Supports formats supported by {@link ImageIO}
|
||||||
* as well as {@link FastImageIO} based on the useFastIO param.
|
* as well as {@link FastImageIO} based on the useFastIO param.
|
||||||
|
|||||||
Reference in New Issue
Block a user