JBoss VFS 3.1.0.Final-redhat-2

org.jboss.vfs
Class VirtualFile

java.lang.Object
  extended by org.jboss.vfs.VirtualFile
All Implemented Interfaces:
Serializable

public final class VirtualFile
extends Object
implements Serializable

A virtual file. This is a symbolic reference to a location in the virtual file system hierarchy. Holding a VirtualFile instance gives no guarantees as to the presence or immutability of the referenced file or any of its parent path elements.

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

Method Summary
 URI asDirectoryURI()
          Get file's URI as a directory.
 URL asDirectoryURL()
          Get file's URL as a directory.
 URI asFileURI()
          Get file's URI as a file.
 URL asFileURL()
          Get file's URL as a file.
 boolean delete()
          Delete this virtual file
 boolean equals(Object o)
          Determine whether the given object is equal to this one.
 boolean equals(VirtualFile o)
          Determine whether the given object is equal to this one.
 boolean exists()
          Tests whether the underlying implementation file still exists.
 Certificate[] getCertificates()
          Get the Certificates for the virtual file.
 VirtualFile getChild(String path)
          Get a child virtual file.
 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
 CodeSigner[] getCodeSigners()
          Get the CodeSigners for a the virtual file.
 long getLastModified()
          When the file was last modified
 String getLowerCaseName()
          Deprecated. should not be used anymore, as the code is case-sensitive from JBVFS-170
 String getName()
          Get the simple VF name (X.java)
 VirtualFile getParent()
          Get a VirtualFile which represents the parent of this instance.
 List<VirtualFile> getParentFileList()
          Get the all the parent files of this virtual file from this file to the root as a list.
 VirtualFile[] getParentFiles()
          Get the all the parent files of this virtual file from this file to the root.
 String getPathName()
          Get the absolute VFS full path name (/xxx/yyy/foo.ear/baz.jar/org/jboss/X.java)
 String getPathNameRelativeTo(VirtualFile parent)
          Get the path name relative to a parent virtual file.
 File getPhysicalFile()
          Get a physical file for this virtual file.
 long getSize()
          Get the size
 int hashCode()
          Get a hashcode for this virtual file.
 boolean isDirectory()
          Determine whether the named virtual file is a directory.
 boolean isFile()
          Determine whether the named virtual file is a plain file.
 boolean isLeaf()
          Deprecated. use isDirectory() or isFile() instead
 boolean isRoot()
          Determines whether this virtual file represents a true root of a file system.
 InputStream openStream()
          Access the file contents.
 String toString()
          Get a human-readable (but non-canonical) representation of this virtual file.
 URI toURI()
          Get file's current URI.
 URL toURL()
          Get file's current URL.
 void visit(VirtualFileVisitor visitor)
          Visit the virtual file system
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getName

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

Returns:
the simple file name

getLowerCaseName

public String getLowerCaseName()
Deprecated. should not be used anymore, as the code is case-sensitive from JBVFS-170

Get the simple VF name mapped to lowercase (x.java) (used by case-insensitive filesystems like ZIP).

Returns:
the lowercase simple file name

getPathName

public String getPathName()
Get the absolute VFS full path name (/xxx/yyy/foo.ear/baz.jar/org/jboss/X.java)

Returns:
the VFS full path name

getPathNameRelativeTo

public String getPathNameRelativeTo(VirtualFile parent)
                             throws IllegalArgumentException
Get the path name relative to a parent virtual file. If the given virtual file is not a parent of this virtual file, then an IllegalArgumentException is thrown.

Parameters:
parent - the parent virtual file
Returns:
the relative path name as a string
Throws:
IllegalArgumentException - if the given virtual file is not a parent of this virtual file

getLastModified

public long getLastModified()
When the file was last modified

Returns:
the last modified time

getSize

public long getSize()
Get the size

Returns:
the size

exists

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

Returns:
true if the file exists, false otherwise.

isRoot

public boolean isRoot()
Determines whether this virtual file represents a true root of a file system. On UNIX, there is only one root "/". Howevever, on Windows there are an infinite number of roots that correspond to drives, or UNC paths.

Returns:
true if this represents a root.

isLeaf

@Deprecated
public boolean isLeaf()
Deprecated. use isDirectory() or isFile() instead

Whether it is a simple leaf of the VFS, i.e. whether it can contain other files

Returns:
true if a simple file

isFile

public boolean isFile()
Determine whether the named virtual file is a plain file.

Returns:
true if it is a plain file, false otherwise

isDirectory

public boolean isDirectory()
Determine whether the named virtual file is a directory.

Returns:
true if it is a directory, false otherwise

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

delete

public boolean delete()
Delete this virtual file

Returns:
true if file was deleted

getPhysicalFile

public File getPhysicalFile()
                     throws IOException
Get a physical file for this virtual file. Depending on the underlying file system type, this may simply return an already-existing file; it may create a copy of a file; or it may reuse a preexisting copy of the file. Furthermore, the retured file may or may not have any relationship to other files from the same or any other virtual directory.

Returns:
the physical file
Throws:
IOException - if an I/O error occurs while producing the physical file

getParent

public VirtualFile getParent()
Get a VirtualFile which represents the parent of this instance.

Returns:
the parent or null if there is no parent

getParentFiles

public VirtualFile[] getParentFiles()
Get the all the parent files of this virtual file from this file to the root. The leafmost file will be at the start of the array, and the rootmost will be at the end.

Returns:
the array of parent files

getParentFileList

public List<VirtualFile> getParentFileList()
Get the all the parent files of this virtual file from this file to the root as a list. The leafmost file will be at the start of the list, and the rootmost will be at the end.

Returns:
the list of parent files

getChildren

public List<VirtualFile> getChildren()
Get the children. This is the combined list of real children within this directory, as well as virtual children created by submounts.

Returns:
the children

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

getChild

public VirtualFile getChild(String path)
Get a child virtual file. The child may or may not exist in the virtual filesystem.

Parameters:
path - the path
Returns:
the child
Throws:
IllegalArgumentException - if the path is null

toURL

public URL toURL()
          throws MalformedURLException
Get file's current URL. Note: if this VirtualFile refers to a directory at the time of this method invocation, a trailing slash will be appended to the URL; this means that invoking this method may require a filesystem access, and in addition, may not produce consistent results over time.

Returns:
the current url
Throws:
MalformedURLException - if the URL is somehow malformed
See Also:
asDirectoryURL(), asFileURL()

toURI

public URI toURI()
          throws URISyntaxException
Get file's current URI. Note: if this VirtualFile refers to a directory at the time of this method invocation, a trailing slash will be appended to the URI; this means that invoking this method may require a filesystem access, and in addition, may not produce consistent results over time.

Returns:
the current uri
Throws:
URISyntaxException - if the URI is somehow malformed
See Also:
asDirectoryURI(), asFileURI()

asDirectoryURL

public URL asDirectoryURL()
                   throws MalformedURLException
Get file's URL as a directory. There will always be a trailing "/" character.

Returns:
the url
Throws:
MalformedURLException - if the URL is somehow malformed

asDirectoryURI

public URI asDirectoryURI()
                   throws URISyntaxException
Get file's URI as a directory. There will always be a trailing "/" character.

Returns:
the uri
Throws:
URISyntaxException - if the URI is somehow malformed

asFileURL

public URL asFileURL()
              throws MalformedURLException
Get file's URL as a file. There will be no trailing "/" character unless this VirtualFile represents a root.

Returns:
the url
Throws:
MalformedURLException - if the URL is somehow malformed

asFileURI

public URI asFileURI()
              throws URISyntaxException
Get file's URI as a file. There will be no trailing "/" character unless this VirtualFile represents a root.

Returns:
the url
Throws:
URISyntaxException - if the URI is somehow malformed

getCodeSigners

public CodeSigner[] getCodeSigners()
Get the CodeSigners for a the virtual file.

Returns:
the CodeSigners for the virtual file, or null if not signed

getCertificates

public Certificate[] getCertificates()
Get the Certificates for the virtual file. Simply extracts the certificate entries from the code signers array.

Returns:
the certificates for the virtual file, or null if not signed

toString

public String toString()
Get a human-readable (but non-canonical) representation of this virtual file.

Overrides:
toString in class Object
Returns:
the string

equals

public boolean equals(Object o)
Determine whether the given object is equal to this one. Returns true if the argument is a VirtualFile from the same VFS instance with the same name.

Overrides:
equals in class Object
Parameters:
o - the other object
Returns:
true if they are equal

equals

public boolean equals(VirtualFile o)
Determine whether the given object is equal to this one. Returns true if the argument is a VirtualFile from the same VFS instance with the same name.

Parameters:
o - the other virtual file
Returns:
true if they are equal

hashCode

public int hashCode()
Get a hashcode for this virtual file.

Overrides:
hashCode in class Object
Returns:
the hash code

JBoss VFS 3.1.0.Final-redhat-2

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