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 Sat, 08 May 2004 19:48:30 GMT
imario      2004/05/08 12:48:30

  Modified:    vfs/src/java/org/apache/commons/vfs/provider
                        AbstractFileObject.java AbstractFileSystem.java
                        DefaultFileContent.java
               vfs/src/java/org/apache/commons/vfs/cache
                        DefaultFilesCache.java NullFilesCache.java
                        SoftRefFilesCache.java
               vfs/src/java/org/apache/commons/vfs FilesCache.java
               vfs/src/test/org/apache/commons/vfs/test
                        ProviderTestSuite.java
               vfs/src/java/org/apache/commons/vfs/impl
                        VirtualFileSystem.java
               vfs/src/java/org/apache/commons/vfs/provider/zip
                        ZipFileSystem.java
  Log:
  allow programmed removal of file from cache.
  Refactored put/get method names to
  putFileToCache/getFileFromCache for better readability
  
  Revision  Changes    Path
  1.37      +49 -4     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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- AbstractFileObject.java	3 May 2004 19:48:47 -0000	1.36
  +++ AbstractFileObject.java	8 May 2004 19:48:30 -0000	1.37
  @@ -573,6 +573,12 @@
               throw new FileSystemException("vfs.provider/delete-read-only.error", name);
           }
   
  +        if (type == FileType.IMAGINARY)
  +        {
  +            // File does not exist
  +            return;
  +        }
  +
           try
           {
               // Delete the file
  @@ -979,11 +985,29 @@
               {
                   attached = false;
                   type = null;
  -                children = null;
  +
  +                removeChildrenCache();
  +                // children = null;
               }
           }
       }
   
  +    private void removeChildrenCache()
  +    {
  +        /*
  +        if (children != null)
  +        {
  +            for (int iterChildren = 0; iterChildren < children.length; iterChildren++)
  +            {
  +                fs.removeFileFromCache(children[iterChildren].getName());
  +            }
  +
  +            children = null;
  +        }
  +        */
  +        children = null;
  +    }
  +
       /**
        * Attaches to the file.
        */
  @@ -1042,6 +1066,8 @@
           {
               // Fix up state
               type = newType;
  +
  +            removeChildrenCache();
               children = EMPTY_FILE_ARRAY;
   
               // Notify subclass
  @@ -1065,7 +1091,8 @@
           {
               // Fix up state
               type = FileType.IMAGINARY;
  -            children = null;
  +            removeChildrenCache();
  +            // children = null;
   
               // Notify subclass
               onChange();
  @@ -1087,7 +1114,8 @@
       {
           // TODO - this may be called when not attached
   
  -        children = null;
  +        removeChildrenCache();
  +        // children = null;
           onChildrenChanged();
       }
   
  @@ -1103,7 +1131,9 @@
               if (parentName != null)
               {
                   // Locate the parent, if it is cached
  -                parent = (AbstractFileObject) fs.getFile(name.getParent());
  +                parent = (AbstractFileObject) fs.getFileFromCache(parentName);
  +
  +                System.err.println("find parent: " + parentName.toString() + " found: "
+ parent);
               }
           }
   
  @@ -1185,5 +1215,20 @@
                   selected.add(index, file);
               }
           }
  +    }
  +
  +    /**
  +     * Check if the content stream is open
  +     *
  +     * @return true it this is the case
  +     */
  +    public boolean isContentOpen()
  +    {
  +        if (content == null)
  +        {
  +            return false;
  +        }
  +
  +        return content.isOpen();
       }
   }
  
  
  
  1.24      +14 -6     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java
  
  Index: AbstractFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileSystem.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- AbstractFileSystem.java	3 May 2004 19:48:47 -0000	1.23
  +++ AbstractFileSystem.java	8 May 2004 19:48:30 -0000	1.24
  @@ -123,7 +123,7 @@
       /**
        * Adds a file object to the cache.
        */
  -    protected void putFile(final FileObject file)
  +    protected void putFileToCache(final FileObject file)
       {
           files.putFile(file);
           // files.put(file.getName(), file);
  @@ -132,13 +132,21 @@
       /**
        * Returns a cached file.
        */
  -    protected FileObject getFile(final FileName name)
  +    protected FileObject getFileFromCache(final FileName name)
       {
           return files.getFile(this, name);
           // return (FileObject) files.get(name);
       }
   
       /**
  +     * remove a cached file.
  +     */
  +    protected void removeFileFromCache(final FileName name)
  +    {
  +        files.removeFile(this, name);
  +    }
  +
  +    /**
        * Determines if this file system has a particular capability.
        */
       public boolean hasCapability(final Capability capability)
  @@ -205,8 +213,8 @@
               throw new FileSystemException("vfs.provider/mismatched-fs-for-name.error",
new Object[]{name, rootName});
           }
   
  -        // imario@apache.org ==> use getFile
  -        FileObject file = getFile(name);
  +        // imario@apache.org ==> use getFileFromCache
  +        FileObject file = getFileFromCache(name);
           // FileObject file = (FileObject) files.get(name);
           if (file == null)
           {
  @@ -219,8 +227,8 @@
                   throw new FileSystemException("vfs.provider/create-file.error", name);
               }
   
  -            // imario@apache.org ==> use putFile
  -            putFile(file);
  +            // imario@apache.org ==> use putFileToCache
  +            putFileToCache(file);
               // files.put(name, file);
           }
           return file;
  
  
  
  1.19      +10 -0     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
  
  Index: DefaultFileContent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- DefaultFileContent.java	1 May 2004 18:14:26 -0000	1.18
  +++ DefaultFileContent.java	8 May 2004 19:48:30 -0000	1.19
  @@ -331,6 +331,16 @@
       }
   
       /**
  +     * check if a input and/or output stream is open.
  +     *
  +     * @return true if this is the case
  +     */
  +    public boolean isOpen()
  +    {
  +        return state != STATE_NONE;
  +    }
  +
  +    /**
        * An input stream for reading content.  Provides buffering, and
        * end-of-stream monitoring.
        */
  
  
  
  1.2       +7 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/cache/DefaultFilesCache.java
  
  Index: DefaultFilesCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/cache/DefaultFilesCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultFilesCache.java	3 May 2004 19:48:47 -0000	1.1
  +++ DefaultFilesCache.java	8 May 2004 19:48:30 -0000	1.2
  @@ -69,4 +69,10 @@
       {
           filesystemCache.clear();
       }
  +
  +    public void removeFile(FileSystem filesystem, FileName name)
  +    {
  +        Map files = getOrCreateFilesystemCache(filesystem);
  +        files.remove(name);
  +    }
   }
  
  
  
  1.2       +5 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/cache/NullFilesCache.java
  
  Index: NullFilesCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/cache/NullFilesCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NullFilesCache.java	3 May 2004 19:48:47 -0000	1.1
  +++ NullFilesCache.java	8 May 2004 19:48:30 -0000	1.2
  @@ -51,4 +51,8 @@
       public void clear()
       {
       }
  +
  +    public void removeFile(FileSystem filesystem, FileName name)
  +    {
  +    }
   }
  
  
  
  1.2       +6 -1      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java
  
  Index: SoftRefFilesCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SoftRefFilesCache.java	7 May 2004 19:09:56 -0000	1.1
  +++ SoftRefFilesCache.java	8 May 2004 19:48:30 -0000	1.2
  @@ -189,6 +189,11 @@
           }
       }
   
  +    public void removeFile(FileSystem filesystem, FileName name)
  +    {
  +        removeFile(new FileSystemAndNameKey(filesystem, name));
  +    }
  +
       private void removeFile(final FileSystemAndNameKey key)
       {
           synchronized (this)
  
  
  
  1.2       +10 -1     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FilesCache.java
  
  Index: FilesCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FilesCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilesCache.java	3 May 2004 19:48:48 -0000	1.1
  +++ FilesCache.java	8 May 2004 19:48:30 -0000	1.2
  @@ -15,6 +15,7 @@
    */
   package org.apache.commons.vfs;
   
  +
   /**
    * The fileCache interface
    *
  @@ -47,4 +48,12 @@
        * purge the whole cache
        */
       public void clear();
  +
  +    /**
  +     * removes a file from cache
  +     *
  +     * @param filesystem filesystem
  +     * @param name       filename
  +     */
  +    public void removeFile(final FileSystem filesystem, final FileName name);
   }
  
  
  
  1.18      +4 -1      jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java
  
  Index: ProviderTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ProviderTestSuite.java	3 May 2004 19:48:49 -0000	1.17
  +++ ProviderTestSuite.java	8 May 2004 19:48:30 -0000	1.18
  @@ -21,6 +21,7 @@
   import org.apache.commons.AbstractVfsTestCase;
   import org.apache.commons.vfs.FileName;
   import org.apache.commons.vfs.FileObject;
  +import org.apache.commons.vfs.cache.SoftRefFilesCache;
   import org.apache.commons.vfs.impl.DefaultFileReplicator;
   import org.apache.commons.vfs.impl.DefaultFileSystemManager;
   import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
  @@ -140,6 +141,8 @@
   
           // Create the file system manager
           manager = new DefaultFileSystemManager();
  +
  +        manager.setFilesCache(new SoftRefFilesCache());
   
           final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir);
           manager.setReplicator(new PrivilegedFileReplicator(replicator));
  
  
  
  1.14      +4 -4      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/VirtualFileSystem.java
  
  Index: VirtualFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/VirtualFileSystem.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- VirtualFileSystem.java	3 May 2004 19:48:47 -0000	1.13
  +++ VirtualFileSystem.java	8 May 2004 19:48:30 -0000	1.14
  @@ -115,7 +115,7 @@
               junctions.put(junctionName, targetFile);
   
               // Attach to file
  -            final DelegateFileObject junctionFile = (DelegateFileObject) getFile(junctionName);
  +            final DelegateFileObject junctionFile = (DelegateFileObject) getFileFromCache(junctionName);
               if (junctionFile != null)
               {
                   junctionFile.setFile(targetFile);
  @@ -128,11 +128,11 @@
                    !done && parentName != null;
                    childName = parentName, parentName = parentName.getParent())
               {
  -                DelegateFileObject file = (DelegateFileObject) getFile(parentName);
  +                DelegateFileObject file = (DelegateFileObject) getFileFromCache(parentName);
                   if (file == null)
                   {
                       file = new DelegateFileObject(parentName, this, null);
  -                    putFile(file);
  +                    putFileToCache(file);
                   }
                   else
                   {
  
  
  
  1.27      +5 -5      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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ZipFileSystem.java	3 May 2004 19:48:49 -0000	1.26
  +++ ZipFileSystem.java	8 May 2004 19:48:30 -0000	1.27
  @@ -75,15 +75,15 @@
   
               // Create the file
               ZipFileObject fileObj;
  -            if (entry.isDirectory() && getFile(name) != null)
  +            if (entry.isDirectory() && getFileFromCache(name) != null)
               {
  -                fileObj = (ZipFileObject) getFile(name);
  +                fileObj = (ZipFileObject) getFileFromCache(name);
                   fileObj.setZipEntry(entry);
                   continue;
               }
   
               fileObj = createZipFileObject(name, entry, zipFile);
  -            putFile(fileObj);
  +            putFileToCache(fileObj);
   
               // Make sure all ancestors exist
               // TODO - create these on demand
  @@ -93,11 +93,11 @@
                    fileObj = parent, parentName = parentName.getParent())
               {
                   // Locate the parent
  -                parent = (ZipFileObject) getFile(parentName);
  +                parent = (ZipFileObject) getFileFromCache(parentName);
                   if (parent == null)
                   {
                       parent = createZipFileObject(parentName, null, zipFile);
  -                    putFile(parent);
  +                    putFileToCache(parent);
                   }
   
                   // Attach child to parent
  
  
  

---------------------------------------------------------------------
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