Author: rgoers
Date: Sun Sep 25 05:00:37 2011
New Revision: 1175296

URL: http://svn.apache.org/viewvc?rev=1175296&view=rev
Log:
ZipFileSystem now uses an internal HashMap to cache FileObjects that are in the 
zip archive

Modified:
    
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java?rev=1175296&r1=1175295&r2=1175296&view=diff
==============================================================================
--- 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
 (original)
+++ 
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java
 Sun Sep 25 05:00:37 2011
@@ -21,13 +21,16 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.vfs2.Capability;
+import org.apache.commons.vfs2.FileName;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystem;
 import org.apache.commons.vfs2.FileSystemException;
@@ -50,6 +53,11 @@ public class ZipFileSystem extends Abstr
     private final File file;
     private ZipFile zipFile;
 
+    /**
+     * Cache doesn't need to be synchronized since it is read-only.
+     */
+    private Map<FileName, FileObject> cache = new HashMap<FileName, 
FileObject>();
+
   public ZipFileSystem(final AbstractFileName rootName,
                          final FileObject parentLayer,
                          final FileSystemOptions fileSystemOptions)
@@ -198,6 +206,30 @@ public class ZipFileSystem extends Abstr
     }
 
     /**
+     * Adds a file object to the cache.
+     */
+    protected void putFileToCache(final FileObject file)
+    {
+        cache.put(file.getName(), file);
+    }
+
+    /**
+     * Returns a cached file.
+     */
+    protected FileObject getFileFromCache(final FileName name)
+    {
+        return cache.get(name);
+    }
+
+    /**
+     * remove a cached file.
+     */
+    protected void removeFileFromCache(final FileName name)
+    {
+        cache.remove(name);
+    }
+
+    /**
      * will be called after all file-objects closed their streams.
     protected void notifyAllStreamsClosed()
     {

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1175296&r1=1175295&r2=1175296&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Sun Sep 25 05:00:37 2011
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.1" date="TBD" description="">
+      <action issue="VFS-352" dev="rgoers" type="fix">
+        ZipFileSystem now uses an internal Map as a cache for all the files in 
the zip archive.
+      </action>
       <action issue="VFS-351" dev="rgoers" type="fix" due-to="John Backstrand">
         Chain the SftpException in the FileSystemException.
       </action>


Reply via email to