com.partnersoft.io.vfs
Interface VfsDirectory

All Superinterfaces:
VfsNode
All Known Implementing Classes:
AbstractVfsDirectory, NonexistentVfsDirectory

public interface VfsDirectory
extends VfsNode

A directory in a Virtual File System (Vfs).

VFSDirectories act just like directories in a typical filesystem. They can contain other files or subdirectories. From a behavioral perspective, VFSDirectories serve as the focus of listing and finding activities in a Vfs.

Methods starting with "list" list the directory's direct children only (not nodes beneath subdirectories). These methods are analogous to the Unix "ls" command.

Methods starting with "find" list the directory's direct children and also descendents in subdirectories (and subdirectories of the subdirectories, and so forth). These methods are analogous to the Unix "find" command.

"List" and "find" methods with no arguments return all items of the specified type. Those that end with "Like" and take a regular-expression argument allow you to filter the results, e.g.

 results = vfsdir.listFilesLike("*.txt");
 

Methods starting with "create" create a VfsDirectory or VfsFile with the given name or path. This directory or file does not have to exist.

Concrete implementations of VfsDirectory are provided by a VFSModule.

Copyright 2006 Partner Software, Inc.

Author:
Paul Reavis

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 path)
          Creates a new subdirectory address object, placed relative to this directory according to the given path.
 VfsDirectory directoryFor(java.lang.String pathString)
          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 exists()
          Whether the Vfs node exists.
 VfsFile fileFor(Path path)
          Creates a new file address object, placed within relative to this directory according to the given path.
 VfsFile fileFor(java.lang.String pathString)
          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.
 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.
 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.
 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.
 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.
 void remove()
          Removes the directory AND ALL ITS CONTENTS.
 VfsDirectory renameTo(java.lang.String name)
          Renames the directory.
 
Methods inherited from interface com.partnersoft.io.vfs.VfsNode
getAbsolutePath, getBaseName, getDirectory, getExtension, getName, getPath, getUri, getUrl, getVfs, isBackup, isHidden, toFile
 

Method Detail

exists

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 VfsNode
Returns:
true if node exists
Throws:
java.io.IOException - if it can't tell for some reason.

make

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 VfsNode
Throws:
java.io.IOException - if it can't.

directoryNamed

VfsDirectory directoryNamed(java.lang.String name)
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 make() method for that.

Parameters:
name - name of subdirectory
Returns:
new subdirectory

fileNamed

VfsFile fileNamed(java.lang.String name)
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 make() method for that.

Parameters:
name - name of file
Returns:
new file

directoryFor

VfsDirectory directoryFor(Path path)
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 make() method for that.

Parameters:
path - to subdirectory
Returns:
new subdirectory

directoryFor

VfsDirectory directoryFor(java.lang.String pathString)
Same as directoryFor(new Path(pathString)).


fileFor

VfsFile fileFor(Path path)
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 make() method for that.

Parameters:
path - path to file
Returns:
new file

fileFor

VfsFile fileFor(java.lang.String pathString)
Same as fileFor(new Path(pathString)).


listNodes

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

Returns:
list of nodes
Throws:
java.io.IOException - if listing fails

listFiles

java.util.List<VfsFile> listFiles()
                                  throws java.io.IOException
Lists all files (not directories) in this directory. Returns an empty list if the directory does not exist.

Returns:
list of files
Throws:
java.io.IOException

listDirectories

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

Returns:
list of directories
Throws:
java.io.IOException

listNodesLike

java.util.List<VfsNode> listNodesLike(java.lang.String pattern)
                                      throws java.io.IOException
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").

Parameters:
pattern - regular expression pattern
Returns:
list of nodes
Throws:
java.io.IOException
See Also:
Pattern

listFilesLike

java.util.List<VfsFile> listFilesLike(java.lang.String pattern)
                                      throws java.io.IOException
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").

Parameters:
pattern - regular expression pattern
Returns:
list of files
Throws:
java.io.IOException
See Also:
Pattern

listFilesWithExtension

java.util.List<VfsFile> listFilesWithExtension(java.lang.String extension)
                                               throws java.io.IOException
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.

Parameters:
extension - file extension
Returns:
list of files
Throws:
java.io.IOException

listFilesWithBaseName

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

Parameters:
baseName - base name to look for
Returns:
list of files
Throws:
java.io.IOException

listDirectoriesLike

java.util.List<VfsDirectory> listDirectoriesLike(java.lang.String pattern)
                                                 throws java.io.IOException
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").

Parameters:
pattern - regular expression pattern
Returns:
list of directories
Throws:
java.io.IOException
See Also:
Pattern

findNodes

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

Returns:
list of nodes
Throws:
java.io.IOException - if something bad happens

findFiles

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

Returns:
list of files
Throws:
java.io.IOException - if something bad happens

findDirectories

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

Returns:
list of directories
Throws:
java.io.IOException - if something bad happens

findNodesLike

java.util.List<VfsNode> findNodesLike(java.lang.String pattern)
                                      throws java.io.IOException
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").

Parameters:
pattern - regular expression pattern
Returns:
list of nodes
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

findDirectoriesLike

java.util.List<VfsDirectory> findDirectoriesLike(java.lang.String pattern)
                                                 throws java.io.IOException
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").

Parameters:
pattern - regular expression pattern
Returns:
list of directories
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

findFilesLike

java.util.List<VfsFile> findFilesLike(java.lang.String pattern)
                                      throws java.io.IOException
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").

Parameters:
pattern - regular expression pattern
Returns:
list of files
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

findFilesWithExtension

java.util.List<VfsFile> findFilesWithExtension(java.lang.String extension)
                                               throws java.io.IOException
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.

Parameters:
extension - file extension
Returns:
list of files
Throws:
java.io.IOException - if something bad happens
See Also:
Pattern

copyTo

VfsDirectory copyTo(VfsDirectory destination)
                    throws java.io.IOException
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.

Throws:
java.io.IOException

copyTo

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

Throws:
java.io.IOException

remove

void remove()
            throws java.io.IOException
Removes the directory AND ALL ITS CONTENTS. Use with caution.

Throws:
java.io.IOException

renameTo

VfsDirectory renameTo(java.lang.String name)
                      throws java.io.IOException
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.

Throws:
java.io.IOException

moveTo

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

Throws:
java.io.IOException

moveTo

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

Throws:
java.io.IOException