commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip ZipFileSystem.java
Date Thu, 27 Jan 2005 07:15:49 GMT
imario      2005/01/26 23:15:49

  Modified:    vfs/src/java/org/apache/commons/vfs/provider
                        AbstractFileObject.java
               vfs/src/java/org/apache/commons/vfs/provider/tar
                        TarFileSystem.java
               vfs/src/java/org/apache/commons/vfs/provider/zip
                        ZipFileSystem.java
  Log:
  hold strong reference of archive children on the container (parent) fileobject.
  Thus they should only be garbage collected if the parent itself is garbage collected
  
  Revision  Changes    Path
  1.53      +17 -1     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
  
  Index: AbstractFileObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- AbstractFileObject.java	21 Dec 2004 21:54:32 -0000	1.52
  +++ AbstractFileObject.java	27 Jan 2005 07:15:49 -0000	1.53
  @@ -74,7 +74,7 @@
       // go into the global files cache
       // private FileObject[] children;
       private FileName[] children;
  -
  +    private List objects;
   
       protected AbstractFileObject(final FileName name,
                                    final AbstractFileSystem fs)
  @@ -1446,4 +1446,20 @@
       {
           type = fileType;
       }
  +
  +    /**
  +     * This method is meant to add a object where this object holds a strong reference
then.
  +     * E.g. a archive-filesystem creates a list of all childs and they shouldnt get
  +     * garbage collected until the container is garbage collected
  +     * 
  +     * @param strongRef
  +     */
  +    public void holdObject(Object strongRef)
  +    {
  +        if (objects == null)
  +        {
  +            objects = new ArrayList(5);
  +        }
  +        objects.add(strongRef);
  +    }
   }
  
  
  
  1.3       +9 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/tar/TarFileSystem.java
  
  Index: TarFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/tar/TarFileSystem.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TarFileSystem.java	11 Jan 2005 16:14:46 -0000	1.2
  +++ TarFileSystem.java	27 Jan 2005 07:15:49 -0000	1.3
  @@ -27,6 +27,7 @@
   import org.apache.commons.vfs.Selectors;
   import org.apache.commons.vfs.VfsLog;
   import org.apache.commons.vfs.provider.AbstractFileSystem;
  +import org.apache.commons.vfs.provider.AbstractFileObject;
   import org.apache.commons.vfs.provider.bzip2.Bzip2FileObject;
   
   import java.io.File;
  @@ -34,6 +35,8 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.util.Collection;
  +import java.util.List;
  +import java.util.ArrayList;
   import java.util.zip.GZIPInputStream;
   
   /**
  @@ -79,6 +82,7 @@
           // Build the index
           try
           {
  +            List strongRef = new ArrayList(100);
               TarEntry entry;
               while ((entry = getTarFile().getNextEntry()) != null)
               {
  @@ -95,6 +99,7 @@
   
                   fileObj = createTarFileObject(name, entry);
                   putFileToCache(fileObj);
  +                strongRef.add(fileObj);
   
                   // Make sure all ancestors exist
                   // TODO - create these on demand
  @@ -109,12 +114,15 @@
                       {
                           parent = createTarFileObject(parentName, null);
                           putFileToCache(parent);
  +                        strongRef.add(fileObj);
                       }
   
                       // Attach child to parent
                       parent.attachChild(fileObj.getName());
                   }
               }
  +
  +            ((AbstractFileObject) getParentLayer()).holdObject(strongRef);
           }
           catch (IOException e)
           {
  
  
  
  1.32      +7 -0      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java
  
  Index: ZipFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileSystem.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ZipFileSystem.java	4 Jul 2004 18:45:56 -0000	1.31
  +++ ZipFileSystem.java	27 Jan 2005 07:15:49 -0000	1.32
  @@ -25,11 +25,14 @@
   import org.apache.commons.vfs.Selectors;
   import org.apache.commons.vfs.VfsLog;
   import org.apache.commons.vfs.provider.AbstractFileSystem;
  +import org.apache.commons.vfs.provider.AbstractFileObject;
   
   import java.io.File;
   import java.io.IOException;
   import java.util.Collection;
   import java.util.Enumeration;
  +import java.util.List;
  +import java.util.ArrayList;
   import java.util.zip.ZipEntry;
   import java.util.zip.ZipFile;
   
  @@ -74,6 +77,7 @@
           super.init();
   
           // Build the index
  +        List strongRef = new ArrayList(100);
           Enumeration entries = getZipFile().entries();
           while (entries.hasMoreElements())
           {
  @@ -91,6 +95,7 @@
   
               fileObj = createZipFileObject(name, entry);
               putFileToCache(fileObj);
  +            strongRef.add(fileObj);
   
               // Make sure all ancestors exist
               // TODO - create these on demand
  @@ -105,12 +110,14 @@
                   {
                       parent = createZipFileObject(parentName, null);
                       putFileToCache(parent);
  +                    strongRef.add(fileObj);
                   }
   
                   // Attach child to parent
                   parent.attachChild(fileObj.getName());
               }
           }
  +        ((AbstractFileObject) getParentLayer()).holdObject(strongRef);
       }
   
       protected ZipFile getZipFile() throws FileSystemException
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message