org.jboss.virtual
Class VirtualFile

java.lang.Object
  extended by org.jboss.virtual.VirtualFile
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AssembledDirectory

public class VirtualFile
extends java.lang.Object
implements java.io.Serializable

A virtual file as seen by the user

Version:
$Revision: 44334 $
Author:
Scott.Stark@jboss.org, adrian@jboss.org, Ales.Justin@jboss.org
See Also:
Serialized Form

Constructor Summary
VirtualFile(VirtualFileHandler handler)
          Create a new VirtualFile.
 
Method Summary
protected  void checkStreams()
          Check if streams set exist.
 void cleanup()
          Do file cleanup.
 void close()
          Close the file resources (stream, etc.)
 void closeStreams()
          Close the streams
 boolean delete()
          Delete this virtual file
 boolean delete(int gracePeriod)
          Delete this virtual file
 boolean equals(java.lang.Object obj)
           
 boolean exists()
          Tests whether the underlying implementation file still exists.
 VirtualFile findChild(java.lang.String path)
          Deprecated. use getChild, and handle null if not found
 java.security.cert.Certificate[] getCertificates()
          Get certificates.
 VirtualFile getChild(java.lang.String path)
          Get a child
 java.util.List<VirtualFile> getChildren()
          Get the children
 java.util.List<VirtualFile> getChildren(VirtualFileFilter filter)
          Get the children
 java.util.List<VirtualFile> getChildrenRecursively()
          Get all the children recursively
 java.util.List<VirtualFile> getChildrenRecursively(VirtualFileFilter filter)
          Get all the children recursively
 long getLastModified()
          When the file was last modified
 java.lang.String getName()
          Get the simple VF name (X.java)
 VirtualFile getParent()
          Get the parent
 java.lang.String getPathName()
          Get the VFS relative path name (org/jboss/X.java)
 long getSize()
          Get the size
 VFS getVFS()
          Get the VFS instance for this virtual file
 boolean hasBeenModified()
          Returns true if the file has been modified since this method was last called Last modified time is initialized at handler instantiation.
 int hashCode()
           
 boolean isArchive()
          Is the file archive.
 boolean isHidden()
          Whether it is hidden
 boolean isLeaf()
          Whether it is a simple leaf of the VFS, i.e.
 java.io.InputStream openStream()
          Access the file contents.
 java.lang.String toString()
           
 java.net.URI toURI()
          Get the VF URI (file://root/org/jboss/X.java)
 java.net.URL toURL()
          Get the VF URL (file://root/org/jboss/X.java)
 void visit(VirtualFileVisitor visitor)
          Visit the virtual file system
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VirtualFile

public VirtualFile(VirtualFileHandler handler)
Create a new VirtualFile.

Parameters:
handler - the handler
Throws:
java.lang.IllegalArgumentException - if the handler is null
Method Detail

getCertificates

public java.security.cert.Certificate[] getCertificates()
Get certificates.

Returns:
the certificates associated with this virtual file

getName

public java.lang.String getName()
Get the simple VF name (X.java)

Returns:
the simple file name
Throws:
java.lang.IllegalStateException - if the file is closed

getPathName

public java.lang.String getPathName()
Get the VFS relative path name (org/jboss/X.java)

Returns:
the VFS relative path name
Throws:
java.lang.IllegalStateException - if the file is closed

toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException,
                          java.net.URISyntaxException
Get the VF URL (file://root/org/jboss/X.java)

Returns:
the full URL to the VF in the VFS.
Throws:
java.net.MalformedURLException - if a url cannot be parsed
java.net.URISyntaxException - if a uri cannot be parsed
java.lang.IllegalStateException - if the file is closed

toURI

public java.net.URI toURI()
                   throws java.net.MalformedURLException,
                          java.net.URISyntaxException
Get the VF URI (file://root/org/jboss/X.java)

Returns:
the full URI to the VF in the VFS.
Throws:
java.net.URISyntaxException - if a uri cannot be parsed
java.lang.IllegalStateException - if the file is closed
java.net.MalformedURLException - for a bad url

getLastModified

public long getLastModified()
                     throws java.io.IOException
When the file was last modified

Returns:
the last modified time
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

hasBeenModified

public boolean hasBeenModified()
                        throws java.io.IOException
Returns true if the file has been modified since this method was last called Last modified time is initialized at handler instantiation.

Returns:
true if modifed, false otherwise
Throws:
java.io.IOException - for any error

getSize

public long getSize()
             throws java.io.IOException
Get the size

Returns:
the size
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

exists

public boolean exists()
               throws java.io.IOException
Tests whether the underlying implementation file still exists.

Returns:
true if the file exists, false otherwise.
Throws:
java.io.IOException - - thrown on failure to detect existence.

isLeaf

public boolean isLeaf()
               throws java.io.IOException
Whether it is a simple leaf of the VFS, i.e. whether it can contain other files

Returns:
true if a simple file.
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

isArchive

public boolean isArchive()
                  throws java.io.IOException
Is the file archive.

Returns:
true if archive, false otherwise
Throws:
java.io.IOException - for any error

isHidden

public boolean isHidden()
                 throws java.io.IOException
Whether it is hidden

Returns:
true when hidden
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

openStream

public java.io.InputStream openStream()
                               throws java.io.IOException
Access the file contents.

Returns:
an InputStream for the file contents.
Throws:
java.io.IOException - for any error accessing the file system
java.lang.IllegalStateException - if the file is closed

checkStreams

protected void checkStreams()
Check if streams set exist.


closeStreams

public void closeStreams()
Close the streams


cleanup

public void cleanup()
Do file cleanup. e.g. delete temp files


close

public void close()
Close the file resources (stream, etc.)


delete

public boolean delete()
               throws java.io.IOException
Delete this virtual file

Returns:
true if file was deleted
Throws:
java.io.IOException - if an error occurs

delete

public boolean delete(int gracePeriod)
               throws java.io.IOException
Delete this virtual file

Parameters:
gracePeriod - max time to wait for any locks (in milliseconds)
Returns:
true if file was deleted
Throws:
java.io.IOException - if an error occurs

getVFS

public VFS getVFS()
Get the VFS instance for this virtual file

Returns:
the VFS
Throws:
java.lang.IllegalStateException - if the file is closed

getParent

public VirtualFile getParent()
                      throws java.io.IOException
Get the parent

Returns:
the parent or null if there is no parent
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

getChildren

public java.util.List<VirtualFile> getChildren()
                                        throws java.io.IOException
Get the children

Returns:
the children
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

getChildren

public java.util.List<VirtualFile> getChildren(VirtualFileFilter filter)
                                        throws java.io.IOException
Get the children

Parameters:
filter - to filter the children
Returns:
the children
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed or it is a leaf node

getChildrenRecursively

public java.util.List<VirtualFile> getChildrenRecursively()
                                                   throws java.io.IOException
Get all the children recursively

This always uses VisitorAttributes.RECURSE

Returns:
the children
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed

getChildrenRecursively

public java.util.List<VirtualFile> getChildrenRecursively(VirtualFileFilter filter)
                                                   throws java.io.IOException
Get all the children recursively

This always uses VisitorAttributes.RECURSE

Parameters:
filter - to filter the children
Returns:
the children
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalStateException - if the file is closed or it is a leaf node

visit

public void visit(VirtualFileVisitor visitor)
           throws java.io.IOException
Visit the virtual file system

Parameters:
visitor - the visitor
Throws:
java.io.IOException - for any problem accessing the virtual file system
java.lang.IllegalArgumentException - if the visitor is null
java.lang.IllegalStateException - if the file is closed

findChild

@Deprecated
public VirtualFile findChild(java.lang.String path)
                      throws java.io.IOException
Deprecated. use getChild, and handle null if not found

Find a child

Parameters:
path - the path
Returns:
the child
Throws:
java.io.IOException - for any problem accessing the VFS (including the child does not exist)
java.lang.IllegalArgumentException - if the path is null
java.lang.IllegalStateException - if the file is closed or it is a leaf node

getChild

public VirtualFile getChild(java.lang.String path)
                     throws java.io.IOException
Get a child

Parameters:
path - the path
Returns:
the child or null if not found
Throws:
java.io.IOException - for any problem accessing the VFS
java.lang.IllegalArgumentException - if the path is null
java.lang.IllegalStateException - if the file is closed or it is a leaf node

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object