Package org.jboss.vfs
Class VirtualFile
- java.lang.Object
-
- org.jboss.vfs.VirtualFile
-
- All Implemented Interfaces:
java.io.Serializable
public final class VirtualFile extends java.lang.Object implements java.io.SerializableA virtual file. This is a symbolic reference to a location in the virtual file system hierarchy. Holding aVirtualFileinstance gives no guarantees as to the presence or immutability of the referenced file or any of its parent path elements.- Version:
- $Revision: 44334 $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private inthashCodeprivate java.lang.Stringlcnameprivate java.lang.Stringnameprivate VirtualFileparentprivate java.lang.StringpathNameprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description VirtualFile(java.lang.String name, VirtualFile parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.net.URIasDirectoryURI()Get file's URI as a directory.java.net.URLasDirectoryURL()Get file's URL as a directory.java.net.URIasFileURI()Get file's URI as a file.java.net.URLasFileURL()Get file's URL as a file.booleandelete()Delete this virtual fileprivate static <T> TdoIoPrivileged(java.security.PrivilegedExceptionAction<T> action)booleanequals(java.lang.Object o)Determine whether the given object is equal to this one.booleanequals(VirtualFile o)Determine whether the given object is equal to this one.booleanexists()Tests whether the underlying implementation file still exists.java.security.cert.Certificate[]getCertificates()Get theCertificates for the virtual file.VirtualFilegetChild(java.lang.String path)Get a child virtual file.java.util.List<VirtualFile>getChildren()Get the children.java.util.List<VirtualFile>getChildren(VirtualFileFilter filter)Get the childrenjava.util.List<VirtualFile>getChildrenRecursively()Get all the children recursivelyjava.util.List<VirtualFile>getChildrenRecursively(VirtualFileFilter filter)Get all the children recursivelyjava.security.CodeSigner[]getCodeSigners()Get theCodeSigners for a the virtual file.longgetLastModified()When the file was last modifiedjava.lang.StringgetLowerCaseName()Deprecated.should not be used anymore, as the code is case-sensitive from JBVFS-170java.lang.StringgetName()Get the simple VF name (X.java)VirtualFilegetParent()Get aVirtualFilewhich represents the parent of this instance.java.util.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.private VirtualFile[]getParentFiles(int idx)java.lang.StringgetPathName()Get the absolute VFS full path name (/xxx/yyy/foo.ear/baz.jar/org/jboss/X.java)(package private) java.lang.StringgetPathName(boolean url)Get the absolute VFS full path name.java.lang.StringgetPathNameRelativeTo(VirtualFile parent)Get the path name relative to a parent virtual file.private voidgetPathNameRelativeTo(VirtualFile parent, java.lang.StringBuilder builder)java.io.FilegetPhysicalFile()Get a physical file for this virtual file.longgetSize()Get the sizeinthashCode()Get a hashcode for this virtual file.booleanisDirectory()Determine whether the named virtual file is a directory.booleanisFile()Determine whether the named virtual file is a plain file.booleanisLeaf()Deprecated.useisDirectory()orisFile()insteadbooleanisRoot()Determines whether this virtual file represents a true root of a file system.java.io.InputStreamopenStream()Access the file contents.java.lang.StringtoString()Get a human-readable (but non-canonical) representation of this virtual file.java.net.URItoURI()Get file's current URI.java.net.URLtoURL()Get file's current URL.voidvisit(VirtualFileVisitor visitor)Visit the virtual file systemprivate voidvisit(VirtualFileVisitor visitor, boolean root)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
name
private final java.lang.String name
-
lcname
private final java.lang.String lcname
-
parent
private final VirtualFile parent
-
hashCode
private final int hashCode
-
pathName
private java.lang.String pathName
-
-
Constructor Detail
-
VirtualFile
VirtualFile(java.lang.String name, VirtualFile parent)
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the simple VF name (X.java)- Returns:
- the simple file name
-
getLowerCaseName
public java.lang.String getLowerCaseName()
Deprecated.should not be used anymore, as the code is case-sensitive from JBVFS-170Get the simple VF name mapped to lowercase (x.java) (used by case-insensitive filesystems like ZIP).- Returns:
- the lowercase simple file name
-
getPathName
public java.lang.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 java.lang.String getPathNameRelativeTo(VirtualFile parent) throws java.lang.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 anIllegalArgumentExceptionis thrown.- Parameters:
parent- the parent virtual file- Returns:
- the relative path name as a string
- Throws:
java.lang.IllegalArgumentException- if the given virtual file is not a parent of this virtual file
-
getPathNameRelativeTo
private void getPathNameRelativeTo(VirtualFile parent, java.lang.StringBuilder builder)
-
getPathName
java.lang.String getPathName(boolean url)
Get the absolute VFS full path name. If this is a URL then directory entries will have a trailing slash.- Parameters:
url- whether or not this path is being used for a URL- Returns:
- the VFS full path name
-
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:
trueif this represents a root.
-
isLeaf
@Deprecated public boolean isLeaf()
Deprecated.useisDirectory()orisFile()insteadWhether it is a simple leaf of the VFS, i.e. whether it can contain other files- Returns:
trueif a simple file
-
isFile
public boolean isFile()
Determine whether the named virtual file is a plain file.- Returns:
trueif it is a plain file,falseotherwise
-
isDirectory
public boolean isDirectory()
Determine whether the named virtual file is a directory.- Returns:
trueif it is a directory,falseotherwise
-
openStream
public java.io.InputStream openStream() throws java.io.IOExceptionAccess the file contents.- Returns:
- an InputStream for the file contents.
- Throws:
java.io.IOException- for any error accessing the file system
-
delete
public boolean delete()
Delete this virtual file- Returns:
trueif file was deleted
-
getPhysicalFile
public java.io.File getPhysicalFile() throws java.io.IOExceptionGet 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 returned file may or may not have any relationship to other files from the same or any other virtual directory.- Returns:
- the physical file
- Throws:
java.io.IOException- if an I/O error occurs while producing the physical file
-
doIoPrivileged
private static <T> T doIoPrivileged(java.security.PrivilegedExceptionAction<T> action) throws java.io.IOException- Throws:
java.io.IOException
-
getParent
public VirtualFile getParent()
Get aVirtualFilewhich represents the parent of this instance.- Returns:
- the parent or
nullif 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 java.util.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
-
getParentFiles
private VirtualFile[] getParentFiles(int idx)
-
getChildren
public java.util.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 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 systemjava.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 usesVisitorAttributes.RECURSE- Returns:
- the children
- Throws:
java.io.IOException- for any problem accessing the virtual file systemjava.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 usesVisitorAttributes.RECURSE- Parameters:
filter- to filter the children- Returns:
- the children
- Throws:
java.io.IOException- for any problem accessing the virtual file systemjava.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 systemjava.lang.IllegalArgumentException- if the visitor is nulljava.lang.IllegalStateException- if the file is closed
-
visit
private void visit(VirtualFileVisitor visitor, boolean root) throws java.io.IOException
- Throws:
java.io.IOException
-
getChild
public VirtualFile getChild(java.lang.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:
java.lang.IllegalArgumentException- if the path is null
-
toURL
public java.net.URL toURL() throws java.net.MalformedURLExceptionGet 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:
java.net.MalformedURLException- if the URL is somehow malformed- See Also:
asDirectoryURL(),asFileURL()
-
toURI
public java.net.URI toURI() throws java.net.URISyntaxExceptionGet 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:
java.net.URISyntaxException- if the URI is somehow malformed- See Also:
asDirectoryURI(),asFileURI()
-
asDirectoryURL
public java.net.URL asDirectoryURL() throws java.net.MalformedURLExceptionGet file's URL as a directory. There will always be a trailing"/"character.- Returns:
- the url
- Throws:
java.net.MalformedURLException- if the URL is somehow malformed
-
asDirectoryURI
public java.net.URI asDirectoryURI() throws java.net.URISyntaxExceptionGet file's URI as a directory. There will always be a trailing"/"character.- Returns:
- the uri
- Throws:
java.net.URISyntaxException- if the URI is somehow malformed
-
asFileURL
public java.net.URL asFileURL() throws java.net.MalformedURLExceptionGet file's URL as a file. There will be no trailing"/"character unless thisVirtualFilerepresents a root.- Returns:
- the url
- Throws:
java.net.MalformedURLException- if the URL is somehow malformed
-
asFileURI
public java.net.URI asFileURI() throws java.net.URISyntaxExceptionGet file's URI as a file. There will be no trailing"/"character unless thisVirtualFilerepresents a root.- Returns:
- the url
- Throws:
java.net.URISyntaxException- if the URI is somehow malformed
-
getCodeSigners
public java.security.CodeSigner[] getCodeSigners()
Get theCodeSigners for a the virtual file.- Returns:
- the
CodeSigners for the virtual file, ornullif not signed
-
getCertificates
public java.security.cert.Certificate[] getCertificates()
Get theCertificates for the virtual file. Simply extracts the certificate entries from the code signers array.- Returns:
- the certificates for the virtual file, or
nullif not signed
-
toString
public java.lang.String toString()
Get a human-readable (but non-canonical) representation of this virtual file.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string
-
equals
public boolean equals(java.lang.Object o)
Determine whether the given object is equal to this one. Returns true if the argument is aVirtualFilefrom the sameVFSinstance with the same name.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the other object- Returns:
trueif 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 aVirtualFilefrom the sameVFSinstance with the same name.- Parameters:
o- the other virtual file- Returns:
trueif they are equal
-
hashCode
public int hashCode()
Get a hashcode for this virtual file.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
-