public abstract class Path extends java.lang.Object implements java.lang.Comparable<Path>
Paths are, in general, given with the canonical file separator of forward slash, '/'. The filesystems will take care of any necessary translation.
Currently available filesystems:
Modifier and Type | Class and Description |
---|---|
static interface |
Path.FileChannelFactory |
Modifier and Type | Field and Description |
---|---|
protected static char |
_pathSeparatorChar |
protected SchemeMap |
_schemeMap |
protected static char |
_separatorChar |
protected static L10N |
L |
Modifier | Constructor and Description |
---|---|
protected |
Path(Path root)
Creates a new Path object.
|
protected |
Path(SchemeMap map)
Creates a new Path object.
|
Modifier and Type | Method and Description |
---|---|
void |
bind(Path context)
Binds the context to the current path.
|
protected Path |
cacheCopy()
Copy for caching.
|
boolean |
canExecute()
Tests if the file can be read.
|
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
|
void |
clearStatusCache()
Clears any status cache
|
int |
compareTo(Path path) |
Path |
copy() |
PersistentDependency |
createDepend()
Creates a dependency.
|
boolean |
createLink(Path target,
boolean hardLink)
Creates a link named by this path to another path.
|
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) |
protected static java.lang.String |
escapeURL(java.lang.String rawURL) |
boolean |
exists()
Tests if the file exists.
|
Path.FileChannelFactory |
fileChannelFactory() |
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.
|
long |
getBlockCount()
Returns equivalent of struct stat.st_blocks if appropriate.
|
long |
getBlockSize()
Returns equivalent of struct stat.st_blksize if appropriate.
|
protected Path |
getCache(java.lang.String subPath) |
java.security.cert.Certificate[] |
getCertificates()
Returns any signing certificates, e.g.
|
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 |
getDevice()
Returns equivalent of struct stat.st_dev if appropriate.
|
long |
getDeviceId()
Returns equivalent of struct stat.st_rdev if appropriate.
|
long |
getDiskSpaceFree() |
long |
getDiskSpaceTotal() |
static char |
getFileSeparatorChar() |
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 |
getLastStatusChangeTime()
Returns equivalent of struct stat.st_ctime if appropriate.
|
long |
getLength()
Returns the length of the file in bytes.
|
int |
getMode()
Returns equivalent of struct stat.st_mode if appropriate.
|
java.lang.String |
getNativePath()
Returns the native representation of the path.
|
static java.lang.String |
getNewlineString() |
int |
getNumberOfLinks()
Returns equivalent of struct stat.st_nlink if appropriate.
|
java.lang.Object |
getObject()
Returns the object at this path.
|
int |
getOwner() |
Path |
getParent()
Returns the parent path.
|
abstract java.lang.String |
getPath()
Returns the path.
|
static char |
getPathSeparatorChar() |
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.
|
abstract java.lang.String |
getScheme()
Returns the url scheme
|
SchemeMap |
getSchemeMap()
Returns the schemeMap
|
protected static char |
getSeparatorChar() |
java.lang.String |
getTail()
Returns the last segment of the path.
|
java.lang.String |
getURL()
Returns the full url for the given path.
|
int |
getUser()
Returns equivalent of struct stat.st_uid if appropriate.
|
protected static java.lang.String |
getUserDir() |
java.lang.String |
getUserPath()
Returns the last string used as a lookup, if available.
|
java.lang.Object |
getValue()
Gets the object at the path.
|
int |
hashCode() |
boolean |
isBlockDevice()
Tests if the path refers to a block device.
|
boolean |
isCharacterDevice()
Tests if the path refers to a block device.
|
boolean |
isDirectory()
Tests if the path refers to a directory.
|
boolean |
isExecutable()
Tests if the path is marked as executable
|
boolean |
isFIFO()
Tests if the path refers to a FIFO.
|
boolean |
isFile()
Tests if the path refers to a file.
|
boolean |
isHardLink()
Tests if the path refers to a hard link.
|
boolean |
isLink()
Tests if the path refers to a symbolic link.
|
boolean |
isObject()
Tests if the path refers to an object.
|
protected boolean |
isPathCacheable()
Returns true if the path itself is cacheable
|
boolean |
isSocket()
Tests if the path refers to a socket.
|
boolean |
isSymbolicLink()
Tests if the path refers to a symbolic link.
|
static boolean |
isWindows() |
boolean |
isWindowsInsecure()
Returns true for windows security issues.
|
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 name)
Looks up a new path based on the old path.
|
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 |
lookup(java.net.URL url)
Looks up a path by a URL.
|
Path |
lookupChild(java.lang.String name)
Looks up a new path based on the old path.
|
Path |
lookupImpl(java.lang.String userPath,
java.util.Map<java.lang.String,java.lang.Object> newAttributes,
boolean isAllowRoot)
Returns a new path relative to the current one.
|
Path |
lookupNative(java.lang.String name)
Looks up a path using the local filesystem conventions.
|
Path |
lookupNative(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Looks up a native path, adding attributes.
|
java.lang.String |
lookupRelativeNativePath(Path path)
Returns a native path relative to this native path if the passed path
is relative to this path, or an absolute path if the passed path is not
relative to this path.
|
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 |
openFileRandomAccess()
Opens a random-access stream.
|
RandomAccessStream |
openMemoryMappedFile(long fileSize)
Opens a random-access stream.
|
RandomAccessStream |
openRandomAccess()
Opens a random-access stream.
|
ReadStream |
openRead()
Opens a resin ReadStream for reading.
|
StreamImpl |
openReadImpl() |
ReadWritePair |
openReadWrite()
Opens a resin ReadWritePair for reading and writing.
|
ReadWritePair |
openReadWrite(boolean isAutoFlush)
Opens a resin ReadWritePair for reading and writing.
|
void |
openReadWrite(ReadStream is,
WriteStream os)
Opens a resin ReadWritePair for reading and writing.
|
StreamImpl |
openReadWriteImpl() |
WriteStream |
openWrite()
Opens a resin WriteStream for writing.
|
StreamImpl |
openWriteImpl() |
protected void |
putCache(java.lang.String subPath,
Path path) |
java.lang.String |
readLink()
Returns the target path from the link.
|
java.lang.String |
realPath()
Returns the actual path from the link.
|
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.
|
boolean |
renameTo(java.lang.String path)
Renames the file or directory to the name given by the path.
|
protected java.lang.String |
scanScheme(java.lang.String uri)
Returns the scheme portion of a uri.
|
abstract 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.
|
void |
sendfile(java.io.OutputStream os,
long offset,
long length)
Utility to write the contents of this path to the destination stream.
|
static void |
setDefaultSchemeMap(SchemeMap schemeMap) |
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.
|
static void |
setTestWindows(boolean isTest) |
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() |
boolean |
truncate()
Sets the length of the file to zero.
|
boolean |
truncate(long length)
Sets the length of the file.
|
void |
unbind()
unbinds a link.
|
Path |
unwrap() |
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.
|
protected static final L10N L
protected static char _separatorChar
protected static char _pathSeparatorChar
protected SchemeMap _schemeMap
protected Path(Path root)
root
- the new Path root.protected Path(SchemeMap map)
root
- the new Path root.public final Path lookup(java.lang.String name)
name
- relative url to the new pathpublic final Path lookupChild(java.lang.String name)
name
- relative url to the new pathpublic final Path lookup(java.net.URL url)
public Path lookup(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes)
Path only handles scheme:xxx. Subclasses of Path will specialize the xxx.
userPath
- relative or absolute path, essentially any url.newAttributes
- attributes for the new path.protected Path getCache(java.lang.String subPath)
protected void putCache(java.lang.String subPath, Path path)
protected boolean isPathCacheable()
public Path lookupImpl(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes, boolean isAllowRoot)
Path only handles scheme:xxx. Subclasses of Path will specialize the xxx.
userPath
- relative or absolute path, essentially any url.newAttributes
- attributes for the new path.public final Path lookupNative(java.lang.String name)
name
- relative url using local filesystem separators.public Path lookupNative(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> attributes)
public java.lang.String lookupRelativeNativePath(Path path)
public java.util.ArrayList<Path> getResources(java.lang.String name)
public java.util.ArrayList<Path> getResources()
public Path getParent()
protected java.lang.String scanScheme(java.lang.String uri)
public abstract Path schemeWalk(java.lang.String userPath, java.util.Map<java.lang.String,java.lang.Object> newAttributes, java.lang.String newPath, int offset)
userPath
- the user's lookup() path.newAttributes
- the attributes for the new path.newPath
- the lookup() pathoffset
- offset into newPath to start lookup.public java.lang.String getURL()
public abstract java.lang.String getScheme()
public SchemeMap getSchemeMap()
public java.lang.String getHost()
public int getPort()
public abstract java.lang.String getPath()
public java.lang.String getTail()
e.g. for http://www.caucho.com/products/index.html, getTail() returns 'index.html'
public java.lang.String getQuery()
public java.lang.String getNativePath()
public java.lang.String getUserPath()
Path path = Pwd.lookup("/some/dir").lookup("../test.html");
System.out.println(path.getUserPath());
public void setUserPath(java.lang.String userPath)
public java.lang.String getFullPath()
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");
public java.lang.String getRelativePath()
public boolean isWindowsInsecure()
public java.security.cert.Certificate[] getCertificates()
public boolean exists()
public java.lang.String getContentType()
Mime-type ignorant filesystems return 'application/octet-stream'
public boolean isDirectory()
public boolean isFile()
public boolean isLink()
public boolean isSocket()
public boolean isFIFO()
public boolean isBlockDevice()
public boolean isCharacterDevice()
public boolean isExecutable()
public boolean setExecutable(boolean isExecutable)
java.lang.UnsupportedOperationException
public boolean isSymbolicLink()
public boolean isHardLink()
public boolean isObject()
public void clearStatusCache()
public long getLength()
public long getLastModified()
public void setLastModified(long time)
public long getLastAccessTime()
public long getCreateTime()
public boolean canRead()
public boolean canWrite()
public long getDevice()
public long getInode()
public int getMode()
public int getNumberOfLinks()
public int getUser()
public int getGroup()
public long getDeviceId()
public long getBlockSize()
public long getBlockCount()
public long getLastStatusChangeTime()
public boolean canExecute()
public boolean changeGroup(int gid) throws java.io.IOException
java.io.IOException
public boolean changeGroup(java.lang.String groupName) throws java.io.IOException
java.io.IOException
public boolean chmod(int value)
public int getOwner()
public boolean changeOwner(int uid) throws java.io.IOException
java.io.IOException
public boolean changeOwner(java.lang.String ownerName) throws java.io.IOException
java.io.IOException
public long getDiskSpaceFree()
public long getDiskSpaceTotal()
public java.lang.String[] list() throws java.io.IOException
java.io.IOException
public java.util.Iterator<java.lang.String> iterator() throws java.io.IOException
java.io.IOException
public boolean mkdir() throws java.io.IOException
java.io.IOException
public boolean mkdirs() throws java.io.IOException
java.io.IOException
public boolean remove() throws java.io.IOException
java.io.IOException
public boolean removeAll() throws java.io.IOException
java.io.IOException
public boolean truncate() throws java.io.IOException
java.io.IOException
public boolean truncate(long length) throws java.io.IOException
java.io.IOException
public boolean renameTo(Path path) throws java.io.IOException
java.io.IOException
public final boolean renameTo(java.lang.String path) throws java.io.IOException
java.io.IOException
public Path createRoot()
createRoot is useful for restricting JavaScript scripts without resorting to the dreadfully slow security manager.
public void bind(Path context)
public void unbind()
public java.lang.Object getValue() throws java.lang.Exception
A bean filesystem or a mime-type aware filesystem could deserialize the contents of the file.
java.lang.Exception
public void setValue(java.lang.Object obj) throws java.lang.Exception
Normal filesystems will generally do nothing. However, a bean filesystem or a mime-type aware filesystem could serialize the object and store it.
java.lang.Exception
public java.lang.Object getAttribute(java.lang.String name) throws java.io.IOException
java.io.IOException
public java.util.Iterator getAttributeNames() throws java.io.IOException
java.io.IOException
public final ReadStream openRead() throws java.io.IOException
java.io.IOException
public final WriteStream openWrite() throws java.io.IOException
java.io.IOException
public ReadWritePair openReadWrite() throws java.io.IOException
A chat channel, for example, would open its socket using this interface.
java.io.IOException
public ReadWritePair openReadWrite(boolean isAutoFlush) throws java.io.IOException
A chat channel, for example, would open its socket using this interface.
java.io.IOException
public void openReadWrite(ReadStream is, WriteStream os) throws java.io.IOException
A chat channel, for example, would open its socket using this interface.
is
- pre-allocated ReadStream to be initializedos
- pre-allocated WriteStream to be initializedjava.io.IOException
public WriteStream openAppend() throws java.io.IOException
java.io.IOException
public RandomAccessStream openMemoryMappedFile(long fileSize) throws java.io.IOException
java.io.IOException
public Path.FileChannelFactory fileChannelFactory()
public RandomAccessStream openRandomAccess() throws java.io.IOException
java.io.IOException
public RandomAccessStream openFileRandomAccess() throws java.io.IOException
java.io.IOException
public boolean createNewFile() throws java.io.IOException
java.io.IOException
public PersistentDependency createDepend()
public Path createTempFile(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
prefix
- filename prefixsuffix
- filename suffix, defaults to .tmpjava.io.IOException
public boolean createLink(Path target, boolean hardLink) throws java.io.IOException
target
- the target of the linkhardLink
- true if the link should be a hard linkjava.io.IOException
public java.lang.String readLink()
public java.lang.String realPath()
public void writeToStream(java.io.OutputStream os) throws java.io.IOException
os
- destination stream.java.io.IOException
public void writeToStream(OutputStreamWithBuffer os) throws java.io.IOException
os
- destination stream.java.io.IOException
public void sendfile(java.io.OutputStream os, long offset, long length) throws java.io.IOException
os
- destination stream.java.io.IOException
public long getCrc64()
public java.lang.Object getObject() throws java.io.IOException
java.io.IOException
public void setObject(java.lang.Object obj) throws java.io.IOException
java.io.IOException
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public StreamImpl openReadImpl() throws java.io.IOException
java.io.IOException
public StreamImpl openWriteImpl() throws java.io.IOException
java.io.IOException
public StreamImpl openReadWriteImpl() throws java.io.IOException
java.io.IOException
public StreamImpl openAppendImpl() throws java.io.IOException
java.io.IOException
protected static java.lang.String escapeURL(java.lang.String rawURL)
public Path copy()
public Path unwrap()
protected Path cacheCopy()
public int compareTo(Path path)
compareTo
in interface java.lang.Comparable<Path>
public static final void setDefaultSchemeMap(SchemeMap schemeMap)
public static final boolean isWindows()
public static final void setTestWindows(boolean isTest)
protected static final char getSeparatorChar()
public static final char getFileSeparatorChar()
public static final char getPathSeparatorChar()
protected static java.lang.String getUserDir()
public static java.lang.String getNewlineString()