diff options
author | Brian Carlstrom <bdc@google.com> | 2012-11-26 11:22:54 -0800 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-11-26 11:22:55 -0800 |
commit | 610157ba28e83393954a226d3895c5131806c338 (patch) | |
tree | 8e969ee9347c7ad02e4f7568543d7db04cad0c01 /dalvik | |
parent | bcf0a81a927992883f0cb49c1c945141d1261b8b (diff) | |
parent | 6133a233130f3014b65b96ca92a20c2083c713f4 (diff) | |
download | libcore-610157ba28e83393954a226d3895c5131806c338.zip libcore-610157ba28e83393954a226d3895c5131806c338.tar.gz libcore-610157ba28e83393954a226d3895c5131806c338.tar.bz2 |
Merge "Lazy parsing of zip files for Java resources."
Diffstat (limited to 'dalvik')
-rw-r--r-- | dalvik/src/main/java/dalvik/system/DexPathList.java | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java index 048cc83..3b4c100 100644 --- a/dalvik/src/main/java/dalvik/system/DexPathList.java +++ b/dalvik/src/main/java/dalvik/system/DexPathList.java @@ -189,7 +189,7 @@ import static libcore.io.OsConstants.*; * up front. */ for (File file : files) { - ZipFile zip = null; + File zip = null; DexFile dex = null; String name = file.getName(); @@ -202,17 +202,7 @@ import static libcore.io.OsConstants.*; } } else if (name.endsWith(APK_SUFFIX) || name.endsWith(JAR_SUFFIX) || name.endsWith(ZIP_SUFFIX)) { - try { - zip = new ZipFile(file); - } catch (IOException ex) { - /* - * Note: ZipException (a subclass of IOException) - * might get thrown by the ZipFile constructor - * (e.g. if the file isn't actually a zip/jar - * file). - */ - System.logE("Unable to open zip file: " + file, ex); - } + zip = file; try { dex = loadDexFile(file, optimizedDirectory); @@ -372,23 +362,53 @@ import static libcore.io.OsConstants.*; * Element of the dex/resource file path */ /*package*/ static class Element { - public final File file; - public final ZipFile zipFile; - public final DexFile dexFile; + private final File file; + private final File zip; + private final DexFile dexFile; - public Element(File file, ZipFile zipFile, DexFile dexFile) { + private ZipFile zipFile; + private boolean init; + + public Element(File file, File zip, DexFile dexFile) { this.file = file; - this.zipFile = zipFile; + this.zip = zip; this.dexFile = dexFile; } - public URL findResource(String name) { - if ((zipFile == null) || (zipFile.getEntry(name) == null)) { + public synchronized void maybeInit() { + if (init) { + return; + } + + init = true; + + if (zip == null) { /* * Either this element has no zip/jar file (first * clause), or the zip/jar file doesn't have an entry * for the given name (second clause). */ + return; + } + + try { + zipFile = new ZipFile(zip); + } catch (IOException ioe) { + /* + * Note: ZipException (a subclass of IOException) + * might get thrown by the ZipFile constructor + * (e.g. if the file isn't actually a zip/jar + * file). + */ + System.logE("Unable to open zip file: " + file, ioe); + zipFile = null; + } + } + + public URL findResource(String name) { + maybeInit(); + + if (zipFile == null || zipFile.getEntry(name) == null) { return null; } |