Turns out I completely screwed up my measurements, and it is in fact

(much) faster to read the decompressed files as opposed to reading them
in-place from the jar.  At least I double-checked before going too
far.  In case you were wondering, it's *really* fast to simply check
a jar file for an entry that doesn't exist.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1165 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Andrzej Kapolka
2011-05-09 20:47:20 +00:00
parent d46608becd
commit 692ca57250
2 changed files with 17 additions and 62 deletions
@@ -60,31 +60,12 @@ public class FileResourceBundle extends ResourceBundle
* @param source a file object that references our source jar file.
* @param delay if true, the bundle will wait until someone calls {@link #sourceIsReady}
* before allowing access to its resources.
* @param unpackFully if true the bundle will unpack itself fully.
* @param unpack if true the bundle will unpack itself into a temporary directory
*/
public FileResourceBundle (File source, boolean delay, boolean unpackFully)
{
this(source, delay, unpackFully, true);
}
/**
* Constructs a resource bundle with the supplied jar file.
*
* @param source a file object that references our source jar file.
* @param delay if true, the bundle will wait until someone calls {@link #sourceIsReady}
* before allowing access to its resources.
* @param unpackFully if true the bundle will unpack itself fully.
* @param unpackEntries if true and unpackFully is false, individual entries will be
* unpacked into a temporary directory as needed (as opposed to being read directly from
* the jar file).
*/
public FileResourceBundle (
File source, boolean delay, boolean unpackFully, boolean unpackEntries)
public FileResourceBundle (File source, boolean delay, boolean unpack)
{
_source = source;
_unpackEntries = unpackEntries;
if (unpackFully) {
if (unpack) {
String root = stripSuffix(source.getPath());
_unpacked = new File(root + ".stamp");
_cache = new File(root);
@@ -105,25 +86,17 @@ public class FileResourceBundle extends ResourceBundle
public InputStream getResource (String path)
throws IOException
{
// if specified, unpack our resources into a temp directory so that
// we can load them quickly and the file system can cache them sensibly
if (_unpackEntries) {
File rfile = getResourceFile(path);
return (rfile == null) ? null : new FileInputStream(rfile);
}
if (_jarSource == null && resolveJarFile()) {
return null;
}
JarEntry entry = _jarSource.getJarEntry(path);
return (entry == null) ? null : _jarSource.getInputStream(entry);
// unpack our resources into a temp directory so that we can load
// them quickly and the file system can cache them sensibly
File rfile = getResourceFile(path);
return (rfile == null) ? null : new FileInputStream(rfile);
}
@Override
public BufferedImage getImageResource (String path, boolean useFastIO)
throws IOException
{
return _unpackEntries ? ResourceManager.loadImage(getResourceFile(path), useFastIO) :
ResourceManager.loadImage(getResource(path), useFastIO);
return ResourceManager.loadImage(getResourceFile(path), useFastIO);
}
/**
@@ -427,9 +400,6 @@ public class FileResourceBundle extends ResourceBundle
/** The jar file from which we load resources. */
protected JarFile _jarSource;
/** Whether or not to unpack individual entries as needed from the jar file. */
protected boolean _unpackEntries;
/** A directory in which we temporarily unpack our resource files. */
protected static File _tmpdir;
}
@@ -211,7 +211,7 @@ public class ResourceManager
// check a system property to determine if we should unpack our bundles, but don't freak
// out if we fail to read it
try {
_unpackFully = !Boolean.getBoolean("no_unpack_resources");
_unpack = !Boolean.getBoolean("no_unpack_resources");
} catch (SecurityException se) {
// no problem, we're in a sandbox so we definitely won't be unpacking
}
@@ -263,16 +263,7 @@ public class ResourceManager
*/
public void setUnpackResources (boolean unpackResources)
{
_unpackFully = unpackResources;
}
/**
* Configures whether we unpack individual jar entries as opposed to reading them directly from
* the jar.
*/
public void setUnpackEntries (boolean unpackEntries)
{
_unpackEntries = unpackEntries;
_unpack = unpackResources;
}
/**
@@ -449,8 +440,7 @@ public class ResourceManager
public boolean checkBundle (String path)
{
File bfile = getResourceFile(path);
return (bfile == null) ? false : new FileResourceBundle(
bfile, true, _unpackFully, _unpackEntries).isUnpacked();
return (bfile == null) ? false : new FileResourceBundle(bfile, true, _unpack).isUnpacked();
}
/**
@@ -469,8 +459,7 @@ public class ResourceManager
return;
}
final FileResourceBundle bundle = new FileResourceBundle(
bfile, true, _unpackFully, _unpackEntries);
final FileResourceBundle bundle = new FileResourceBundle(bfile, true, _unpack);
if (bundle.isUnpacked()) {
if (bundle.sourceIsReady()) {
listener.requestCompleted(bundle);
@@ -823,8 +812,7 @@ public class ResourceManager
{
if (setType.equals(FILE_SET_TYPE)) {
FileResourceBundle bundle =
createFileResourceBundle(getResourceFile(path),
true, _unpackFully, _unpackEntries);
createFileResourceBundle(getResourceFile(path), true, _unpack);
if (!bundle.isUnpacked() || !bundle.sourceIsReady()) {
dlist.add(bundle);
}
@@ -840,9 +828,9 @@ public class ResourceManager
* Creates an appropriate bundle for fetching resources from files.
*/
protected FileResourceBundle createFileResourceBundle (File source, boolean delay,
boolean unpackFully, boolean unpackEntries)
boolean unpack)
{
return new FileResourceBundle(source, delay, unpackFully, unpackEntries);
return new FileResourceBundle(source, delay, unpack);
}
/**
@@ -1078,11 +1066,8 @@ public class ResourceManager
/** The root path we give to network bundles for all resources they're interested in. */
protected String _networkRootPath;
/** Whether or not to unpack our resource bundles fully. */
protected boolean _unpackFully;
/** Whether or not to unpack individual jar entries. */
protected boolean _unpackEntries = true;
/** Whether or not to unpack our resource bundles. */
protected boolean _unpack;
/** Our default resource set. */
protected ResourceBundle[] _default = new ResourceBundle[0];