com.partnersoft.io.vfs
Class AbstractVfsDirectory

java.lang.Object
  extended by com.partnersoft.io.vfs.AbstractVfsDirectory
All Implemented Interfaces:
VfsDirectory, VfsNode
Direct Known Subclasses:
NonexistentVfsDirectory

public abstract class AbstractVfsDirectory
extends java.lang.Object
implements VfsDirectory

A standard abstract implementation of com.partnersoft.io.VfsDirectory. Includes implementations of the various convenience methods derived from the essential methods, and provides the vfs and path properties.

Most implementations of VfsDirectory should extend this class.

A minimal set of methods has been declared abstract. All other methods are derived from these with default implementations. For example, the various regex-patterned forms of the list and find methods simply call the unpatterned methods and then filter them by checking them against the pattern, returning the result.

Feel free to override these with more efficient implementations if you have such available.

Copyright 2006 Partner Software, Inc.

Version:
$Id: AbstractVfsDirectory.java 2328 2010-01-06 15:38:22Z paul $
Author:
Paul Reavis

Constructor Summary
AbstractVfsDirectory(Vfs vfs, Path path)
          Create a new AbstractVfsDirectory with the given vfs and path.
 
Method Summary
 VfsDirectory copyTo(Path path)
          Does a recursive copy of this directory's contents to the path provided in the same Vfs.
 VfsDirectory copyTo(VfsDirectory destination)
          Does a recursive copy of this directory's contents to the directory provided.
 VfsDirectory directoryFor(Path subPath)
          Creates a new subdirectory address object, placed relative to this directory according to the given path.
 VfsDirectory directoryFor(java.lang.String subPathString)
          Same as directoryFor(new Path(pathString)).
 VfsDirectory directoryNamed(java.lang.String name)
          Creates a new subdirectory address object, placed within this directory, with the given name.
 boolean equals(java.lang.Object nother)
           
abstract  boolean exists()
          Whether the Vfs node exists.
 VfsFile fileFor(Path subPath)
          Creates a new file address object, placed within relative to this directory according to the given path.
 VfsFile fileFor(java.lang.String subPathString)
          Same as fileFor(new Path(pathString)).
 VfsFile fileNamed(java.lang.String name)
          Creates a new file address object, placed within this directory, with the given name.
 java.util.List<VfsDirectory> findDirectories()
          Does a recursive, downward search through the descendents of this directory, returning all directories (not files) found.
 java.util.List<VfsDirectory> findDirectoriesLike(java.lang.String pattern)
          Does a recursive, downward search through the descendents of this directory, returning all directories (not files) found that match the given pattern.
 java.util.List<VfsFile> findFiles()
          Does a recursive, downward search through the descendents of this directory, returning the files (not directories) found.
 java.util.List<VfsFile> findFilesLike(java.lang.String pattern)
          Does a recursive, downward search through the descendents of this directory, returning all files (not directories) found that match the given pattern.
 java.util.List<VfsFile> findFilesWithExtension(java.lang.String extension)
          Does a recursive, downward search through the descendents of this directory, returning all files (not directories) found that have the given extension.
 java.util.List<VfsNode> findNodes()
          Does a recursive, downward search through the descendents of this directory, returning all nodes (files and directories) found.
 java.util.List<VfsNode> findNodesLike(java.lang.String pattern)
          Does a recursive, downward search through the descendents of this directory, returning all nodes (files and directories) found that match the given pattern.
 Path getAbsolutePath()
          The absolute path to the Vfs node.
 java.lang.String getBaseName()
          Base name of node; this is the part before the '.' if there's a file extension.
 VfsDirectory getDirectory()
          The VfsDirectory this node is in, or null if it is the root directory.
 java.lang.String getExtension()
          File extension (the part after the '.' in most file names; includes the '.').
 java.lang.String getName()
          Bare name of node.
 Path getPath()
          The path to the Vfs node.
 Vfs getVfs()
          The Vfs this node is in.
 boolean isBackup()
          True if the file is a backup file - commonly this is based on file name patterns like *~ or *.bak.
 boolean isHidden()
          True if the file is a hidden file - commonly this is based on the file name starting with a ".".
abstract  java.util.List<VfsDirectory> listDirectories()
          Lists all directories (not files) in this directory.
 java.util.List<VfsDirectory> listDirectoriesLike(java.lang.String pattern)
          Lists all directories (not files) in this directory with the given regular expression pattern.
abstract  java.util.List<VfsFile> listFiles()
          Lists all files (not directories) in this directory.
 java.util.List<VfsFile> listFilesLike(java.lang.String pattern)
          Lists all files (not directories) in this directory with the given regular expression pattern.
 java.util.List<VfsFile> listFilesWithBaseName(java.lang.String baseName)
          Lists all files (not directories) in this directory with the basename (name without extension) You should not include the period (.)
 java.util.List<VfsFile> listFilesWithExtension(java.lang.String extension)
          Lists all files (not directories) in this directory with the given extension.
abstract  java.util.List<VfsNode> listNodes()
          Lists all nodes (both directories and files) in this directory.
 java.util.List<VfsNode> listNodesLike(java.lang.String pattern)
          Lists all nodes (both directories and files) in this directory with the given regular expression pattern.
abstract  void make()
          Creates the node and any ancestor directories needed to contain it.
 VfsDirectory moveTo(Path newPath)
          Moves the file to the new path on the same Vfs.
 VfsDirectory moveTo(VfsDirectory destination)
          Moves the file to the destination given.
 VfsDirectory renameTo(java.lang.String name)
          Renames the directory.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.partnersoft.io.vfs.VfsDirectory
remove
 
Methods inherited from interface com.partnersoft.io.vfs.VfsNode
getUri, getUrl, toFile
 

Constructor Detail

AbstractVfsDirectory

public AbstractVfsDirectory(Vfs vfs,
                            Path path)
Create a new AbstractVfsDirectory with the given vfs and path.

Parameters:
vfs - Vfs that the directory is in.
path - path to directory in the Vfs.
Method Detail

exists

public abstract boolean exists()
                        throws java.io.IOException
Description copied from interface: VfsNode
Whether the Vfs node exists. VfsNode objects serve as addresses as well as handles, so they may not point to existing resources. Use VfsNode.make() to create the node if it does not exist.

Specified by:
exists in interface VfsDirectory
Specified by:
exists in interface VfsNode
Returns:
true if node exists
Throws:
java.io.IOException - if it can't tell for some reason.

make

public abstract void make()
                   throws java.io.IOException
Description copied from interface: VfsNode
Creates the node and any ancestor directories needed to contain it.

Specified by:
make in interface VfsDirectory
Specified by:
make in interface VfsNode
Throws:
java.io.IOException - if it can't.

directoryNamed

public VfsDirectory directoryNamed(java.lang.String name)
Description copied from interface: VfsDirectory
Creates a new subdirectory address object, placed within this directory, with the given name. Does NOT interpret the name as a path; create a Path object and use the pathwise version for that.

Note that this creates a new VfsDirectory address object, but does NOT make the actual filesystem directory if it does not exist. Use the VfsDirectory.make() method for that.

Specified by:
directoryNamed in interface VfsDirectory
Parameters:
name - name of subdirectory
Returns:
new subdirectory

fileNamed

public VfsFile fileNamed(java.lang.String name)
Description copied from interface: VfsDirectory
Creates a new file address object, placed within this directory, with the given name. Does NOT interpret the name as a path; create a Path object and use the pathwise version for that.

Note that this creates a new VfsFile address object, but does NOT make the actual file object if it does not exist. Use the VfsDirectory.make() method for that.

Specified by:
fileNamed in interface VfsDirectory
Parameters:
name - name of file
Returns:
new file

directoryFor

public VfsDirectory directoryFor(Path subPath)
Description copied from interface: VfsDirectory
Creates a new subdirectory address object, placed relative to this directory according to the given path.

Note that this creates a new VfsDirectory address object, but does NOT make the actual filesystem directory if it does not exist. Use the VfsDirectory.make() method for that.

Specified by:
directoryFor in interface VfsDirectory
Parameters:
subPath - to subdirectory
Returns:
new subdirectory

fileFor

public VfsFile fileFor(Path subPath)
Description copied from interface: VfsDirectory
Creates a new file address object, placed within relative to this directory according to the given path.

Note that this creates a new VfsFile address object, but does NOT make the actual file object if it does not exist. Use the VfsDirectory.make() method for that.

Specified by:
fileFor in interface VfsDirectory
Parameters:
subPath - path to file
Returns:
new file

directoryFor

public VfsDirectory directoryFor(java.lang.String subPathString)
Description copied from interface: VfsDirectory
Same as directoryFor(new Path(pathString)).

Specified by:
directoryFor in interface VfsDirectory

fileFor

public VfsFile fileFor(java.lang.String subPathString)
Description copied from interface: VfsDirectory
Same as fileFor(new Path(pathString)).

Specified by:
fileFor in interface VfsDirectory

listNodes

public abstract java.util.List<VfsNode> listNodes()
                                           throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all nodes (both directories and files) in this directory. Returns an empty list if the directory does not exist.

Specified by:
listNodes in interface VfsDirectory
Returns:
list of nodes
Throws:
java.io.IOException - if listing fails

listFiles

public abstract java.util.List<VfsFile> listFiles()
                                           throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all files (not directories) in this directory. Returns an empty list if the directory does not exist.

Specified by:
listFiles in interface VfsDirectory
Returns:
list of files
Throws:
java.io.IOException

listDirectories

public abstract java.util.List<VfsDirectory> listDirectories()
                                                      throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all directories (not files) in this directory. Returns an empty list if the directory does not exist.

Specified by:
listDirectories in interface VfsDirectory
Returns:
list of directories
Throws:
java.io.IOException

listNodesLike

public java.util.List<VfsNode> listNodesLike(java.lang.String pattern)
                                      throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all nodes (both directories and files) in this directory with the given regular expression pattern. Note that this is a perl-style regex (e.g. ".\*\.txt"), NOT a glob-style (e.g. "*.txt").

Specified by:
listNodesLike in interface VfsDirectory
Parameters:
pattern - regular expression pattern
Returns:
list of nodes
Throws:
java.io.IOException
See Also:
Pattern

listFilesLike

public java.util.List<VfsFile> listFilesLike(java.lang.String pattern)
                                      throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all files (not directories) in this directory with the given regular expression pattern. Note that this is a perl-style regex (e.g. ".\*\.txt"), NOT a glob-style (e.g. "*.txt").

Specified by:
listFilesLike in interface VfsDirectory
Parameters:
pattern - regular expression pattern
Returns:
list of files
Throws:
java.io.IOException
See Also:
Pattern

listFilesWithExtension

public java.util.List<VfsFile> listFilesWithExtension(java.lang.String extension)
                                               throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all files (not directories) in this directory with the given extension. You should include the period (.) but it will be added if it's missing.

Specified by:
listFilesWithExtension in interface VfsDirectory
Parameters:
extension - file extension
Returns:
list of files
Throws:
java.io.IOException

listFilesWithBaseName

public java.util.List<VfsFile> listFilesWithBaseName(java.lang.String baseName)
                                              throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all files (not directories) in this directory with the basename (name without extension) You should not include the period (.)

Specified by:
listFilesWithBaseName in interface VfsDirectory
Parameters:
baseName - base name to look for
Returns:
list of files
Throws:
java.io.IOException

listDirectoriesLike

public java.util.List<VfsDirectory> listDirectoriesLike(java.lang.String pattern)
                                                 throws java.io.IOException
Description copied from interface: VfsDirectory
Lists all directories (not files) in this directory with the given regular expression pattern. Note that this is a perl-style regex (e.g. ".\*\.txt"), NOT a glob-style (e.g. "*.txt").

Specified by:
listDirectoriesLike in interface VfsDirectory
Parameters:
pattern - regular expression pattern
Returns:
list of directories
Throws:
java.io.IOException
See Also:
Pattern

findNodes

public java.util.List<VfsNode> findNodes()
                                  throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning all nodes (files and directories) found.

Specified by:
findNodes in interface VfsDirectory
Returns:
list of nodes
Throws:
java.io.IOException - if something bad happens

findFiles

public java.util.List<VfsFile> findFiles()
                                  throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning the files (not directories) found.

Specified by:
findFiles in interface VfsDirectory
Returns:
list of files
Throws:
java.io.IOException - if something bad happens

findDirectories

public java.util.List<VfsDirectory> findDirectories()
                                             throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning all directories (not files) found.

Specified by:
findDirectories in interface VfsDirectory
Returns:
list of directories
Throws:
java.io.IOException - if something bad happens

findFilesLike

public java.util.List<VfsFile> findFilesLike(java.lang.String pattern)
                                      throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning all files (not directories) found that match the given pattern. Note that this is a perl-style regex (e.g. ".\*\.txt"), NOT a glob-style (e.g. "*.txt").

Specified by:
findFilesLike in interface VfsDirectory
Parameters:
pattern - regular expression pattern
Returns:
list of files
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

findFilesWithExtension

public java.util.List<VfsFile> findFilesWithExtension(java.lang.String extension)
                                               throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning all files (not directories) found that have the given extension. You should include the period (.) but it will be added if it's missing.

Specified by:
findFilesWithExtension in interface VfsDirectory
Parameters:
extension - file extension
Returns:
list of files
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

findDirectoriesLike

public java.util.List<VfsDirectory> findDirectoriesLike(java.lang.String pattern)
                                                 throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning all directories (not files) found that match the given pattern. Note that this is a perl-style regex (e.g. ".\*\.txt"), NOT a glob-style (e.g. "*.txt").

Specified by:
findDirectoriesLike in interface VfsDirectory
Parameters:
pattern - regular expression pattern
Returns:
list of directories
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

findNodesLike

public java.util.List<VfsNode> findNodesLike(java.lang.String pattern)
                                      throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive, downward search through the descendents of this directory, returning all nodes (files and directories) found that match the given pattern. Note that this is a perl-style regex (e.g. ".\*\.txt"), NOT a glob-style (e.g. "*.txt").

Specified by:
findNodesLike in interface VfsDirectory
Parameters:
pattern - regular expression pattern
Returns:
list of nodes
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

copyTo

public VfsDirectory copyTo(VfsDirectory destination)
                    throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive copy of this directory's contents to the directory provided. Works across Vfs systems, so you can use this to e.g. recursively copy from one filesystem to another, or from a URL source to a filesystem. Does not delete the destination's contents before the copy, and overwrites any existing files as needed, so be cautious. Returns the destination.

Specified by:
copyTo in interface VfsDirectory
Throws:
java.io.IOException

copyTo

public VfsDirectory copyTo(Path path)
                    throws java.io.IOException
Description copied from interface: VfsDirectory
Does a recursive copy of this directory's contents to the path provided in the same Vfs. Returns the resulting directory name.

Specified by:
copyTo in interface VfsDirectory
Throws:
java.io.IOException

renameTo

public VfsDirectory renameTo(java.lang.String name)
                      throws java.io.IOException
Description copied from interface: VfsDirectory
Renames the directory. Returns a new VfsDirectory pointing to the new location. This is not the same as a move; it can only affect the final filename, not the rest of the path.

Specified by:
renameTo in interface VfsDirectory
Throws:
java.io.IOException

moveTo

public VfsDirectory moveTo(Path newPath)
                    throws java.io.IOException
Description copied from interface: VfsDirectory
Moves the file to the new path on the same Vfs. Returns a new VfsDirectory pointing to the new location.

Specified by:
moveTo in interface VfsDirectory
Throws:
java.io.IOException

moveTo

public VfsDirectory moveTo(VfsDirectory destination)
                    throws java.io.IOException
Description copied from interface: VfsDirectory
Moves the file to the destination given. Does not work if the destination already exists. Works across Vfs systems. Returns the destination.

Specified by:
moveTo in interface VfsDirectory
Throws:
java.io.IOException

toString

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

getPath

public Path getPath()
Description copied from interface: VfsNode
The path to the Vfs node.

Specified by:
getPath in interface VfsNode
Returns:
path to Vfs node.

getAbsolutePath

public Path getAbsolutePath()
Description copied from interface: VfsNode
The absolute path to the Vfs node. This has different meanings in different contexts.

Specified by:
getAbsolutePath in interface VfsNode

getVfs

public Vfs getVfs()
Description copied from interface: VfsNode
The Vfs this node is in.

Specified by:
getVfs in interface VfsNode
Returns:
Vfs this node is in.

getName

public java.lang.String getName()
Description copied from interface: VfsNode
Bare name of node. name = baseName + extension

Specified by:
getName in interface VfsNode
Returns:
name of node.

getBaseName

public java.lang.String getBaseName()
Description copied from interface: VfsNode
Base name of node; this is the part before the '.' if there's a file extension. name = baseName + extension

Specified by:
getBaseName in interface VfsNode

getExtension

public java.lang.String getExtension()
Description copied from interface: VfsNode
File extension (the part after the '.' in most file names; includes the '.'). Returns the blank string "" if there is none. name = baseName + extension

Specified by:
getExtension in interface VfsNode

getDirectory

public VfsDirectory getDirectory()
Description copied from interface: VfsNode
The VfsDirectory this node is in, or null if it is the root directory.

Specified by:
getDirectory in interface VfsNode

isBackup

public boolean isBackup()
Description copied from interface: VfsNode
True if the file is a backup file - commonly this is based on file name patterns like *~ or *.bak.

Specified by:
isBackup in interface VfsNode

isHidden

public boolean isHidden()
Description copied from interface: VfsNode
True if the file is a hidden file - commonly this is based on the file name starting with a ".".

Specified by:
isHidden in interface VfsNode

equals

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