com.caucho.vfs
Class PathWrapper

java.lang.Object
  extended by com.caucho.vfs.Path
      extended by com.caucho.vfs.PathWrapper
All Implemented Interfaces:
java.lang.Comparable<Path>
Direct Known Subclasses:
SpyPath

public abstract class PathWrapper
extends Path

Wraps a path object.


Field Summary
protected static L10N L
           
 
Fields inherited from class com.caucho.vfs.Path
_pathSeparatorChar, _schemeMap, _separatorChar
 
Constructor Summary
protected PathWrapper(Path path)
          Creates a new Path object.
 
Method Summary
 void bind(Path context)
          Binds the context to the current path.
 boolean canRead()
          Tests if the file can be read.
 boolean canWrite()
          Tests if the file can be written.
 boolean changeGroup(int gid)
          Changes the group
 boolean changeGroup(java.lang.String groupName)
          Changes the group
 boolean changeOwner(int uid)
          Changes the owner
 boolean changeOwner(java.lang.String ownerName)
          Changes the owner
 boolean chmod(int value)
          Changes the permissions
 boolean createNewFile()
          Creates the file named by this Path and returns true if the file is new.
 Path createRoot()
          Creates a restricted root, like the Unix chroot call.
 Path createRoot(SchemeMap schemeMap)
           
 Path createTempFile(java.lang.String prefix, java.lang.String suffix)
          Creates a unique temporary file as a child of this directory.
 boolean equals(java.lang.Object o)
           
 boolean exists()
          Tests if the file exists.
 java.lang.Object getAttribute(java.lang.String name)
          Gets an attribute of the object.
 java.util.Iterator getAttributeNames()
          Returns a iterator of all attribute names set for this object.
 java.lang.String getContentType()
          Returns the mime-type of the file.
 long getCrc64()
          Returns the crc64 code.
 long getCreateTime()
          Returns the create time of the file.
 long getDiskSpaceFree()
           
 long getDiskSpaceTotal()
           
 java.lang.String getFullPath()
          Returns the full path, including the restricted root.
 int getGroup()
          Returns equivalent of struct stat.st_gid if appropriate.
 java.lang.String getHost()
          Returns the hostname
 long getInode()
          Returns equivalent of struct stat.st_ino if appropriate.
 long getLastAccessTime()
          Returns the last access time of the file.
 long getLastModified()
          Returns the last modified time of the file.
 long getLength()
          Returns the length of the file in bytes.
 java.lang.String getNativePath()
          Returns the native representation of the path.
 java.lang.Object getObject()
          Returns the object at this path.
 int getOwner()
           
 Path getParent()
          Returns the parent path.
 java.lang.String getPath()
          Returns the path.
 int getPort()
          Returns the port.
 java.lang.String getQuery()
          Returns the query string of the path.
 java.lang.String getRelativePath()
          For union paths like MergePath, return the relative path into that path.
 java.util.ArrayList<Path> getResources()
          Looks up all the existing resources.
 java.util.ArrayList<Path> getResources(java.lang.String name)
          Looks up all the resources matching a name.
 java.lang.String getScheme()
          Returns the url scheme
 java.lang.String getTail()
          Returns the last segment of the path.
 java.lang.String getURL()
          Returns the full url for the given path.
 java.lang.String getUserPath()
          Returns the last string used as a lookup, if available.
 java.lang.Object getValue()
          Gets the object at the path.
 Path getWrappedPath()
          Returns the wrapped path.
 int hashCode()
           
 boolean isDirectory()
          Tests if the path refers to a directory.
 boolean isExecutable()
          Tests if the path is marked as executable
 boolean isFile()
          Tests if the path refers to a file.
 boolean isObject()
          Tests if the path refers to an object.
 java.util.Iterator<java.lang.String> iterator()
          Returns a jdk1.2 Iterator for the contents of this directory.
 java.lang.String[] list()
           
 Path lookup(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes)
          Returns a new path relative to the current one.
 Path lookupImpl(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes)
          Returns a new path relative to the current one.
 Path lookupNative(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> attributes)
          Looks up a native path, adding attributes.
 boolean mkdir()
          Creates the directory named by this path.
 boolean mkdirs()
          Creates the directory named by this path and any parent directories.
 WriteStream openAppend()
          Opens a resin stream for appending.
 StreamImpl openAppendImpl()
           
 RandomAccessStream openRandomAccess()
          Opens a random-access stream.
 StreamImpl openReadImpl()
           
 ReadWritePair openReadWrite()
          Opens a resin ReadWritePair for reading and writing.
 void openReadWrite(ReadStream is, WriteStream os)
          Opens a resin ReadWritePair for reading and writing.
 StreamImpl openReadWriteImpl()
           
 StreamImpl openWriteImpl()
           
 boolean remove()
          Removes the file or directory named by this path.
 boolean removeAll()
          Removes the all files and directories below this path.
 boolean renameTo(Path path)
          Renames the file or directory to the name given by the path.
 Path schemeWalk(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes, java.lang.String newPath, int offset)
          Path-specific lookup.
 boolean setExecutable(boolean isExecutable)
          Change the executable status of the of the path.
 void setLastModified(long time)
           
 void setObject(java.lang.Object obj)
          Sets the object at this path.
 void setUserPath(java.lang.String userPath)
          Sets the user path.
 void setValue(java.lang.Object obj)
          Sets the object at the path.
 java.lang.String toString()
           
 void unbind()
          unbinds a link.
 void writeToStream(java.io.OutputStream os)
          Utility to write the contents of this path to the destination stream.
 void writeToStream(OutputStreamWithBuffer os)
          Utility to write the contents of this path to the destination stream.
 
Methods inherited from class com.caucho.vfs.Path
cacheCopy, canExecute, clearStatusCache, compareTo, copy, createDepend, createLink, escapeURL, getBlockCount, getBlockSize, getCache, getCertificates, getDevice, getDeviceId, getFileSeparatorChar, getLastStatusChangeTime, getMode, getNewlineString, getNumberOfLinks, getPathSeparatorChar, getSchemeMap, getSeparatorChar, getUser, getUserDir, isBlockDevice, isCharacterDevice, isFIFO, isHardLink, isLink, isPathCacheable, isSocket, isSymbolicLink, isWindows, isWindowsInsecure, lookup, lookup, lookupNative, lookupRelativeNativePath, openFileRandomAccess, openMemoryMappedFile, openRead, openReadWrite, openWrite, putCache, readLink, realPath, renameTo, scanScheme, setDefaultSchemeMap, setTestWindows, truncate, truncate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

L

protected static final L10N L
Constructor Detail

PathWrapper

protected PathWrapper(Path path)
Creates a new Path object.

Parameters:
path - the new Path root.
Method Detail

getWrappedPath

public Path getWrappedPath()
Returns the wrapped path.


lookup

public Path lookup(java.lang.String userPath,
                   java.util.Map<java.lang.String,java.lang.Object> newAttributes)
Returns a new path relative to the current one.

Path only handles scheme:xxx. Subclasses of Path will specialize the xxx.

Overrides:
lookup in class Path
Parameters:
userPath - relative or absolute path, essentially any url.
newAttributes - attributes for the new path.
Returns:
the new path or null if the scheme doesn't exist

lookupImpl

public Path lookupImpl(java.lang.String userPath,
                       java.util.Map<java.lang.String,java.lang.Object> newAttributes)
Returns a new path relative to the current one.

Path only handles scheme:xxx. Subclasses of Path will specialize the xxx.

Overrides:
lookupImpl in class Path
Parameters:
userPath - relative or absolute path, essentially any url.
newAttributes - attributes for the new path.
Returns:
the new path or null if the scheme doesn't exist

lookupNative

public Path lookupNative(java.lang.String name,
                         java.util.Map<java.lang.String,java.lang.Object> attributes)
Looks up a native path, adding attributes.

Overrides:
lookupNative in class Path

getResources

public java.util.ArrayList<Path> getResources(java.lang.String name)
Looks up all the resources matching a name. (Generally only useful with MergePath.

Overrides:
getResources in class Path

getResources

public java.util.ArrayList<Path> getResources()
Looks up all the existing resources. (Generally only useful with MergePath.

Overrides:
getResources in class Path

getParent

public Path getParent()
Returns the parent path.

Overrides:
getParent in class Path

schemeWalk

public Path schemeWalk(java.lang.String userPath,
                       java.util.Map<java.lang.String,java.lang.Object> newAttributes,
                       java.lang.String newPath,
                       int offset)
Path-specific lookup. Path implementations will override this.

Specified by:
schemeWalk in class Path
Parameters:
userPath - the user's lookup() path.
newAttributes - the attributes for the new path.
newPath - the lookup() path
offset - offset into newPath to start lookup.
Returns:
the found path

getURL

public java.lang.String getURL()
Returns the full url for the given path.

Overrides:
getURL in class Path

getScheme

public java.lang.String getScheme()
Returns the url scheme

Specified by:
getScheme in class Path

getHost

public java.lang.String getHost()
Returns the hostname

Overrides:
getHost in class Path

getPort

public int getPort()
Returns the port.

Overrides:
getPort in class Path

getPath

public java.lang.String getPath()
Returns the path. e.g. for HTTP, returns the part after the host and port.

Specified by:
getPath in class Path

getTail

public java.lang.String getTail()
Returns the last segment of the path.

e.g. for http://www.caucho.com/products/index.html, getTail() returns 'index.html'

Overrides:
getTail in class Path

getQuery

public java.lang.String getQuery()
Returns the query string of the path.

Overrides:
getQuery in class Path

getNativePath

public java.lang.String getNativePath()
Returns the native representation of the path. On Windows, getNativePath() returns 'd:\\foo\bar.html', getPath() returns '/d:/foo/bar.html'

Overrides:
getNativePath in class Path

getUserPath

public java.lang.String getUserPath()
Returns the last string used as a lookup, if available. This allows parsers to give intelligent error messages, with the user's path instead of the whole path. The following will print '../test.html':
 Path path = Pwd.lookup("/some/dir").lookup("../test.html");
 System.out.println(path.getUserPath());
 

Overrides:
getUserPath in class Path

setUserPath

public void setUserPath(java.lang.String userPath)
Sets the user path. Useful for temporary files caching another URL.

Overrides:
setUserPath in class Path

getFullPath

public java.lang.String getFullPath()
Returns the full path, including the restricted root.

For the following, path.getPath() returns '/file.html', while path.getFullPath() returns '/chroot/file.html'.

 Path chroot = Pwd.lookup("/chroot").createRoot();
 Path path = chroot.lookup("/file.html");
 

Overrides:
getFullPath in class Path

getRelativePath

public java.lang.String getRelativePath()
For union paths like MergePath, return the relative path into that path.

Overrides:
getRelativePath in class Path

exists

public boolean exists()
Tests if the file exists.

Overrides:
exists in class Path

getContentType

public java.lang.String getContentType()
Returns the mime-type of the file.

Mime-type ignorant filesystems return 'application/octet-stream'

Overrides:
getContentType in class Path

isDirectory

public boolean isDirectory()
Tests if the path refers to a directory.

Overrides:
isDirectory in class Path

isFile

public boolean isFile()
Tests if the path refers to a file.

Overrides:
isFile in class Path

isObject

public boolean isObject()
Tests if the path refers to an object.

Overrides:
isObject in class Path

getLength

public long getLength()
Returns the length of the file in bytes.

Overrides:
getLength in class Path
Returns:
0 for non-files

getLastModified

public long getLastModified()
Returns the last modified time of the file. According to the jdk, this may not correspond to the system time.

Overrides:
getLastModified in class Path
Returns:
0 for non-files.

setLastModified

public void setLastModified(long time)
Overrides:
setLastModified in class Path

getLastAccessTime

public long getLastAccessTime()
Returns the last access time of the file.

Overrides:
getLastAccessTime in class Path
Returns:
0 for non-files.

getCreateTime

public long getCreateTime()
Returns the create time of the file.

Overrides:
getCreateTime in class Path
Returns:
0 for non-files.

canRead

public boolean canRead()
Tests if the file can be read.

Overrides:
canRead in class Path

canWrite

public boolean canWrite()
Tests if the file can be written.

Overrides:
canWrite in class Path

chmod

public boolean chmod(int value)
Changes the permissions

Overrides:
chmod in class Path
Returns:
true if successful

list

public java.lang.String[] list()
                        throws java.io.IOException
Overrides:
list in class Path
Returns:
The contents of this directory or null if the path does not refer to a directory.
Throws:
java.io.IOException

iterator

public java.util.Iterator<java.lang.String> iterator()
                                              throws java.io.IOException
Returns a jdk1.2 Iterator for the contents of this directory.

Overrides:
iterator in class Path
Throws:
java.io.IOException

mkdir

public boolean mkdir()
              throws java.io.IOException
Creates the directory named by this path.

Overrides:
mkdir in class Path
Returns:
true if successful.
Throws:
java.io.IOException

mkdirs

public boolean mkdirs()
               throws java.io.IOException
Creates the directory named by this path and any parent directories.

Overrides:
mkdirs in class Path
Returns:
true if successful.
Throws:
java.io.IOException

remove

public boolean remove()
               throws java.io.IOException
Removes the file or directory named by this path.

Overrides:
remove in class Path
Returns:
true if successful.
Throws:
java.io.IOException

removeAll

public boolean removeAll()
                  throws java.io.IOException
Removes the all files and directories below this path.

Overrides:
removeAll in class Path
Returns:
true if successful.
Throws:
java.io.IOException

renameTo

public boolean renameTo(Path path)
                 throws java.io.IOException
Renames the file or directory to the name given by the path.

Overrides:
renameTo in class Path
Returns:
true if successful
Throws:
java.io.IOException

createRoot

public Path createRoot()
Creates a restricted root, like the Unix chroot call. Restricted roots cannot access schemes, so file:/etc/passwd cannot be used.

createRoot is useful for restricting JavaScript scripts without resorting to the dreadfully slow security manager.

Overrides:
createRoot in class Path

createRoot

public Path createRoot(SchemeMap schemeMap)
Overrides:
createRoot in class Path

bind

public void bind(Path context)
Binds the context to the current path. Later lookups will return the new context instead of the current path. Essentially, this is a software symbolic link.

Overrides:
bind in class Path

unbind

public void unbind()
unbinds a link.

Overrides:
unbind in class Path

getValue

public java.lang.Object getValue()
                          throws java.lang.Exception
Gets the object at the path. Normal filesystems will generally typically return null.

A bean filesystem or a mime-type aware filesystem could deserialize the contents of the file.

Overrides:
getValue in class Path
Throws:
java.lang.Exception

setValue

public void setValue(java.lang.Object obj)
              throws java.lang.Exception
Sets the object at the path.

Normal filesystems will generally do nothing. However, a bean filesystem or a mime-type aware filesystem could serialize the object and store it.

Overrides:
setValue in class Path
Throws:
java.lang.Exception

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws java.io.IOException
Gets an attribute of the object.

Overrides:
getAttribute in class Path
Throws:
java.io.IOException

getAttributeNames

public java.util.Iterator getAttributeNames()
                                     throws java.io.IOException
Returns a iterator of all attribute names set for this object.

Overrides:
getAttributeNames in class Path
Returns:
null if path has no attributes.
Throws:
java.io.IOException

openReadWrite

public ReadWritePair openReadWrite()
                            throws java.io.IOException
Opens a resin ReadWritePair for reading and writing.

A chat channel, for example, would open its socket using this interface.

Overrides:
openReadWrite in class Path
Throws:
java.io.IOException

openReadWrite

public void openReadWrite(ReadStream is,
                          WriteStream os)
                   throws java.io.IOException
Opens a resin ReadWritePair for reading and writing.

A chat channel, for example, would open its socket using this interface.

Overrides:
openReadWrite in class Path
Parameters:
is - pre-allocated ReadStream to be initialized
os - pre-allocated WriteStream to be initialized
Throws:
java.io.IOException

openAppend

public WriteStream openAppend()
                       throws java.io.IOException
Opens a resin stream for appending.

Overrides:
openAppend in class Path
Throws:
java.io.IOException

openRandomAccess

public RandomAccessStream openRandomAccess()
                                    throws java.io.IOException
Opens a random-access stream.

Overrides:
openRandomAccess in class Path
Throws:
java.io.IOException

createNewFile

public boolean createNewFile()
                      throws java.io.IOException
Creates the file named by this Path and returns true if the file is new.

Overrides:
createNewFile in class Path
Throws:
java.io.IOException

createTempFile

public Path createTempFile(java.lang.String prefix,
                           java.lang.String suffix)
                    throws java.io.IOException
Creates a unique temporary file as a child of this directory.

Overrides:
createTempFile in class Path
Parameters:
prefix - filename prefix
suffix - filename suffix, defaults to .tmp
Returns:
Path to the new file.
Throws:
java.io.IOException

writeToStream

public void writeToStream(java.io.OutputStream os)
                   throws java.io.IOException
Utility to write the contents of this path to the destination stream.

Overrides:
writeToStream in class Path
Parameters:
os - destination stream.
Throws:
java.io.IOException

writeToStream

public void writeToStream(OutputStreamWithBuffer os)
                   throws java.io.IOException
Utility to write the contents of this path to the destination stream.

Overrides:
writeToStream in class Path
Parameters:
os - destination stream.
Throws:
java.io.IOException

getCrc64

public long getCrc64()
Returns the crc64 code.

Overrides:
getCrc64 in class Path

getObject

public java.lang.Object getObject()
                           throws java.io.IOException
Returns the object at this path. Normally, only paths like JNDI will support this.

Overrides:
getObject in class Path
Throws:
java.io.IOException

setObject

public void setObject(java.lang.Object obj)
               throws java.io.IOException
Sets the object at this path. Normally, only paths like JNDI will support this.

Overrides:
setObject in class Path
Throws:
java.io.IOException

getInode

public long getInode()
Description copied from class: Path
Returns equivalent of struct stat.st_ino if appropriate.

Overrides:
getInode in class Path

isExecutable

public boolean isExecutable()
Description copied from class: Path
Tests if the path is marked as executable

Overrides:
isExecutable in class Path

setExecutable

public boolean setExecutable(boolean isExecutable)
Description copied from class: Path
Change the executable status of the of the path.

Overrides:
setExecutable in class Path

getGroup

public int getGroup()
Description copied from class: Path
Returns equivalent of struct stat.st_gid if appropriate.

Overrides:
getGroup in class Path

changeGroup

public boolean changeGroup(int gid)
                    throws java.io.IOException
Description copied from class: Path
Changes the group

Overrides:
changeGroup in class Path
Throws:
java.io.IOException

changeGroup

public boolean changeGroup(java.lang.String groupName)
                    throws java.io.IOException
Description copied from class: Path
Changes the group

Overrides:
changeGroup in class Path
Throws:
java.io.IOException

getOwner

public int getOwner()
Overrides:
getOwner in class Path

changeOwner

public boolean changeOwner(int uid)
                    throws java.io.IOException
Description copied from class: Path
Changes the owner

Overrides:
changeOwner in class Path
Returns:
true if successful
Throws:
java.io.IOException

changeOwner

public boolean changeOwner(java.lang.String ownerName)
                    throws java.io.IOException
Description copied from class: Path
Changes the owner

Overrides:
changeOwner in class Path
Returns:
true if successful
Throws:
java.io.IOException

getDiskSpaceFree

public long getDiskSpaceFree()
Overrides:
getDiskSpaceFree in class Path

getDiskSpaceTotal

public long getDiskSpaceTotal()
Overrides:
getDiskSpaceTotal in class Path

hashCode

public int hashCode()
Overrides:
hashCode in class Path

equals

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

toString

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

openReadImpl

public StreamImpl openReadImpl()
                        throws java.io.IOException
Overrides:
openReadImpl in class Path
Throws:
java.io.IOException

openWriteImpl

public StreamImpl openWriteImpl()
                         throws java.io.IOException
Overrides:
openWriteImpl in class Path
Throws:
java.io.IOException

openReadWriteImpl

public StreamImpl openReadWriteImpl()
                             throws java.io.IOException
Overrides:
openReadWriteImpl in class Path
Throws:
java.io.IOException

openAppendImpl

public StreamImpl openAppendImpl()
                          throws java.io.IOException
Overrides:
openAppendImpl in class Path
Throws:
java.io.IOException