[jboss-cvs] container/src/main/org/jboss/vfs/file ...

Scott Stark scott.stark at jboss.com
Wed Jul 12 20:22:06 EDT 2006


  User: starksm 
  Date: 06/07/12 20:22:06

  Modified:    src/main/org/jboss/vfs/file   FileSystemVFS.java
                        FileImpl.java
  Log:
  Add support for serialization of VirtualFiles for the file protocol
  
  Revision  Changes    Path
  1.6       +56 -24    container/src/main/org/jboss/vfs/file/FileSystemVFS.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FileSystemVFS.java
  ===================================================================
  RCS file: /cvsroot/jboss/container/src/main/org/jboss/vfs/file/FileSystemVFS.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- FileSystemVFS.java	4 May 2006 14:49:38 -0000	1.5
  +++ FileSystemVFS.java	13 Jul 2006 00:22:06 -0000	1.6
  @@ -19,6 +19,7 @@
   import java.net.URL;
   import java.util.List;
   import java.util.Iterator;
  +import java.util.WeakHashMap;
   import java.util.concurrent.ConcurrentHashMap;
   import java.util.logging.Level;
   import java.util.logging.Logger;
  @@ -26,17 +27,66 @@
   /** A simple implementation of ReadOnlyVFS that only understands file URLs
    *
    * @author Scott.Stark at jboss.org
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class FileSystemVFS
      implements ReadOnlyVFS
   {
  +   // TODO: jboss logger
      private static Logger log = Logger.getLogger("org.jboss.vfs.file.FileSystemVFS");
  +   /** */
  +   private static WeakHashMap<URL, FileSystemVFS> fileSystems =
  +      new WeakHashMap<URL, FileSystemVFS>();
  +   /** The VFS root URL */
      private URL rootURL;
  +   /** The VirtualFile corresponding to the rootURL */
      private VirtualFile vfsRoot;
      /** Cache of rootURL absolute paths to previously resolved files */
      private ConcurrentHashMap<String, VirtualFile> fileCache;
   
  +   /**
  +    * get VirtualFile from filesystem path
  +    *
  +    * @param fp path, i.e. "/home/wburke/foo.jar"
  +    * @return the VirtualFiel for fileSystemPath
  +    * @throws RuntimeException wrapper for any error  
  +    */
  +   public static VirtualFile getVirtualFile(String fileSystemPath)
  +   {
  +      try
  +      {
  +         File fp = new File(fileSystemPath);
  +         URL parent = fp.getParentFile().toURL();
  +         VFSFactory factory = VFSFactoryLocator.getFactory(parent);
  +         ReadOnlyVFS vfs = factory.getVFS(parent);
  +         return (vfs.resolveFile(fp.getName()));
  +      }
  +      catch (Exception e)
  +      {
  +         throw new RuntimeException(e);
  +      }
  +
  +   }
  +
  +   /**
  +    * Get the FileSystemVFS for the rootURL.
  +    * 
  +    * @param rootURL
  +    * @return
  +    * @throws IOException
  +    */
  +   public static synchronized FileSystemVFS getFileSystemVFS(URL rootURL)
  +      throws IOException
  +   {
  +      FileSystemVFS vfs = fileSystems.get(rootURL);
  +      if( vfs == null )
  +      {
  +         vfs = new FileSystemVFS(rootURL);
  +         fileSystems.put(rootURL, vfs);
  +      }
  +      return vfs;
  +   }
  +
      FileSystemVFS(URL rootURL)
         throws IOException
      {
  @@ -107,6 +157,11 @@
         return scanner;
      }
   
  +   public URL getRootURL()
  +   {
  +      return rootURL;
  +   }
  +
      /**
       * Resolve the given path against the filesystem search context. This first
       * locates the VirtualFile corresponding to the searchContext, and then
  @@ -223,27 +278,4 @@
         return childVF;
      }
   
  -   /**
  -    * get VirtualFile from filesystem path
  -    *
  -    * @param fp path, i.e. "/home/wburke/foo.jar"
  -    * @return
  -    */
  -   public static VirtualFile getVirtualFile(String fileSystemPath)
  -   {
  -      try
  -      {
  -         File fp = new File(fileSystemPath);
  -         URL parent = fp.getParentFile().toURL();
  -         VFSFactory factory = VFSFactoryLocator.getFactory(parent);
  -         ReadOnlyVFS vfs = factory.getVFS(parent);
  -         return (vfs.resolveFile(fp.getName()));
  -      }
  -      catch (Exception e)
  -      {
  -         throw new RuntimeException(e);
  -      }
  -
  -   }
  -
   }
  
  
  
  1.5       +44 -7     container/src/main/org/jboss/vfs/file/FileImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FileImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/container/src/main/org/jboss/vfs/file/FileImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- FileImpl.java	27 Apr 2006 23:04:49 -0000	1.4
  +++ FileImpl.java	13 Jul 2006 00:22:06 -0000	1.5
  @@ -13,6 +13,12 @@
   import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
  +import java.io.ObjectStreamField;
  +import java.io.Serializable;
  +import java.io.ObjectInputStream.GetField;
  +import java.io.ObjectOutputStream.PutField;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.ArrayList;
  @@ -21,18 +27,26 @@
   /** A java.io.File based implementation of VirtualFile
    *
    * @author Scott.Stark at jboss.org
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class FileImpl
  -   implements VirtualFile
  +   implements VirtualFile, Serializable
   {
  +   private static final long serialVersionUID = 1;
  +   /** The class serial fields */
  +   private static final ObjectStreamField[] serialPersistentFields = {
  +      new ObjectStreamField("rootURL", URL.class),
  +      new ObjectStreamField("path", URL.class),
  +      new ObjectStreamField("vfsPath", String.class)
  +   };
  +
      private URL path;
      private String vfsPath;
  -   private InputStream contentIS;
  -   private File file;
  -   private VirtualFile[] children;
  -   private List<VirtualFile> recursiveChildren;
  -   private FileSystemVFS vfs;
  +   private transient FileSystemVFS vfs;
  +   private transient File file;
  +   private transient VirtualFile[] children;
  +   private transient List<VirtualFile> recursiveChildren;
  +   private transient InputStream contentIS;
   
      public FileImpl(URL path, String vfsPath, FileSystemVFS vfs)
      {
  @@ -174,4 +188,27 @@
         VirtualFile child = vfs.getChild(this.path, name);
         return child;
      }
  +
  +   private void writeObject(ObjectOutputStream out)
  +      throws IOException
  +   {
  +      // Write out the serialPersistentFields
  +      PutField fields = out.putFields();
  +      fields.put("rootURL", vfs.getRootURL());
  +      fields.put("path", path);
  +      fields.put("vfsPath", vfsPath);
  +      out.writeFields();
  +   }
  +   private void readObject(ObjectInputStream in)
  +      throws IOException, ClassNotFoundException
  +   {
  +      // Read in the serialPersistentFields
  +      GetField fields = in.readFields();
  +      URL rootURL = (URL) fields.get("rootURL", null);
  +      this.path = (URL) fields.get("path", null);
  +      this.vfsPath = (String) fields.get("vfsPath", null);
  +      // Initialize the transient values
  +      this.file = new File(path.getPath());
  +      this.vfs = FileSystemVFS.getFileSystemVFS(rootURL);
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list