org.jboss.virtual
Class VirtualFile

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

public class VirtualFile
extends Object
implements 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(Object obj)
           
 boolean exists()
          Tests whether the underlying implementation file still exists.
 VirtualFile findChild(String path)
          Deprecated. use getChild, and handle null if not found
 VirtualFile getChild(String path)
          Get a child
 List<VirtualFile> getChildren()
          Get the children
 List<VirtualFile> getChildren(VirtualFileFilter filter)
          Get the children
 List<VirtualFile> getChildrenRecursively()
          Get all the children recursively
 List<VirtualFile> getChildrenRecursively(VirtualFileFilter filter)
          Get all the children recursively
 long getLastModified()
          When the file was last modified
 String getName()
          Get the simple VF name (X.java)
 VirtualFile getParent()
          Get the parent
 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.
 InputStream openStream()
          Access the file contents.
 String toString()
           
 URI toURI()
          Get the VF URI (file://root/org/jboss/X.java)
 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:
IllegalArgumentException - if the handler is null
Method Detail

getName

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

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

getPathName

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

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

toURL

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

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

toURI

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

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

getLastModified

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

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

hasBeenModified

public boolean hasBeenModified()
                        throws 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:
IOException - for any error

getSize

public long getSize()
             throws IOException
Get the size

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

exists

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

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

isLeaf

public boolean isLeaf()
               throws 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:
IOException - for any problem accessing the virtual file system
IllegalStateException - if the file is closed

isArchive

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

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

isHidden

public boolean isHidden()
                 throws IOException
Whether it is hidden

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

openStream

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

Returns:
an InputStream for the file contents.
Throws:
IOException - for any error accessing the file system
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 IOException
Delete this virtual file

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

delete

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

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

getVFS

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

Returns:
the VFS
Throws:
IllegalStateException - if the file is closed

getParent

public VirtualFile getParent()
                      throws IOException
Get the parent

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

getChildren

public List<VirtualFile> getChildren()
                              throws IOException
Get the children

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

getChildren

public List<VirtualFile> getChildren(VirtualFileFilter filter)
                              throws IOException
Get the children

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

getChildrenRecursively

public List<VirtualFile> getChildrenRecursively()
                                         throws IOException
Get all the children recursively

This always uses VisitorAttributes.RECURSE

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

getChildrenRecursively

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

This always uses VisitorAttributes.RECURSE

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

visit

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

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

findChild

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

Find a child

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

getChild

public VirtualFile getChild(String path)
                     throws IOException
Get a child

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

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2011 JBoss, A division of Red Hat, Inc. All Rights Reserved.