| java.lang.Object com.methodhead.res.FileManager
FileManager | public class FileManager (Code) | | Provides a logical file system and methods to manage it.
|
Method Summary | |
public void | addDirectory(String name, File dir) Adds a directory to the file system. | protected boolean | canOverwrite(File src, File dest) Returns true if src can overwrite dest. | protected boolean | canOverwrite(File dest, boolean isDir) Returns true if dest can be overwritten by a file, where
isDir specifies whether that file is a file or a directory. | public void | copy(String srcPath, String[] srcFiles, String destPath, String destFile) Copies the files specified by srcPath and srcFiles to
destPath. | protected static void | copyFile(File from, File to) Copies from to to; if from is a directory, it
is recursively copied. | public void | create(String path, String file, boolean isDir) Creates the file specified by srcPath and srcFile; a
directory is created if isDir is true, otherwise an
empty file is created. | public void | create(String path, String file, InputStream in) Creates the file specified by srcPath and srcFile,
writing the contents of in to the file. | public void | delete(String srcPath, String[] srcFiles) Deletes the files specified by srcPath and srcFiles. | public String[] | findOverwriteFiles(String srcPath, String[] srcFiles, String destPath, String destFile) Returns the names of files in destPath that would be overwritten
by files specified by srcPath and srcFiles in a move or
copy operation. | public Directory[] | getDirectories() Returns the directories being managed by the file manager, sorted by the
directory name. | public File | getFile(String path, String name) Returns the file specified by path and name, or
null if no such file exists. | protected File | getFileForPath(String path) Returns the directory specified by path, or null if no
such directory (if a file exists, but is not a directory, null is
still returned). | public File[] | getFiles(String path) Returns the files in the directory specified by path, sorted in
alphabetical order, or null if no such path exists. | public File | getNewFile(String path, String name) Returns a file specified by path and name, such that the
returned file can be used to create a new file. | protected boolean | isDestSubdir(String srcPath, String[] srcFiles, String destPath) Returns true if destPath is a subdirectory of any files
specified by srcPath and srcFiles. | public void | move(String srcPath, String[] srcFiles, String destPath, String destFile) Moves the files specified by srcPath and srcFiles to
destPath. | public String | validateCreate(String srcPath, String srcFile, boolean isDir) Validates whether the files specified by srcPath and
srcFile can be created. | public String | validateMove(String srcPath, String[] srcFiles, String destPath, String destFile) Validates moving srcFiles from srcPath to
destPath. |
VALIDATE_CANTOVERWRITE | final public static String VALIDATE_CANTOVERWRITE(Code) | | The move or copy would result in overwriting a directory or overwriting a
file with a directory.
|
VALIDATE_INVALIDDESTNAME | final public static String VALIDATE_INVALIDDESTNAME(Code) | | The destination file name is invalid.
|
VALIDATE_INVALIDDESTPATH | final public static String VALIDATE_INVALIDDESTPATH(Code) | | The destination path is blank, invalid (e.g., contains ".."), or
non-existant.
|
VALIDATE_SUBDIROFSELF | final public static String VALIDATE_SUBDIROFSELF(Code) | | The destination path is a subdirectory of one of the files being moved or
copied.
|
addDirectory | public void addDirectory(String name, File dir) throws ResException(Code) | | Adds a directory to the file system. An exception is thrown if
dir is not a valid directory, or if a directory named
name has already been added.
|
canOverwrite | protected boolean canOverwrite(File src, File dest)(Code) | | Returns true if src can overwrite dest.
Directories cannot be overwritten at all, and files can't be overwritten
by directories.
|
canOverwrite | protected boolean canOverwrite(File dest, boolean isDir)(Code) | | Returns true if dest can be overwritten by a file, where
isDir specifies whether that file is a file or a directory. If
dest is null, it is assumed the file doesn't exist, and
true is returned. The same rules described in
FileManager.canOverwrite(java.io.File,java.io.File) apply.
|
copy | public void copy(String srcPath, String[] srcFiles, String destPath, String destFile)(Code) | | Copies the files specified by srcPath and srcFiles to
destPath. If srcFiles contains exactly one file name,
destFile is used as the destination file name. Any directories
are recursively copied.
|
copyFile | protected static void copyFile(File from, File to) throws ResException(Code) | | Copies from to to; if from is a directory, it
is recursively copied. If to is exists and is not a directory,
it is overwritten. If to is exists and is a directory, the
contents of from are copied over the contents of to. If
to exists, but is a directory when from is not (or vice
versa), an exception is thrown.
|
create | public void create(String path, String file, boolean isDir)(Code) | | Creates the file specified by srcPath and srcFile; a
directory is created if isDir is true, otherwise an
empty file is created. If the file exists, an a file is being created,
the existing file is overwritten.
|
create | public void create(String path, String file, InputStream in)(Code) | | Creates the file specified by srcPath and srcFile,
writing the contents of in to the file. If the file exists, the
existing file is overwritten.
|
delete | public void delete(String srcPath, String[] srcFiles)(Code) | | Deletes the files specified by srcPath and srcFiles. An
exception is thrown if file(s) do not already exist.
|
findOverwriteFiles | public String[] findOverwriteFiles(String srcPath, String[] srcFiles, String destPath, String destFile)(Code) | | Returns the names of files in destPath that would be overwritten
by files specified by srcPath and srcFiles in a move or
copy operation. If srcFiles contains only one file name,
destFile is considered the destination file name.
|
getDirectories | public Directory[] getDirectories()(Code) | | Returns the directories being managed by the file manager, sorted by the
directory name.
|
getFileForPath | protected File getFileForPath(String path) throws ResException(Code) | | Returns the directory specified by path, or null if no
such directory (if a file exists, but is not a directory, null is
still returned).
|
getFiles | public File[] getFiles(String path) throws ResException(Code) | | Returns the files in the directory specified by path, sorted in
alphabetical order, or null if no such path exists.
|
getNewFile | public File getNewFile(String path, String name) throws ResException(Code) | | Returns a file specified by path and name, such that the
returned file can be used to create a new file. An exception is thrown if
the file already exists.
|
isDestSubdir | protected boolean isDestSubdir(String srcPath, String[] srcFiles, String destPath)(Code) | | Returns true if destPath is a subdirectory of any files
specified by srcPath and srcFiles.
|
move | public void move(String srcPath, String[] srcFiles, String destPath, String destFile)(Code) | | Moves the files specified by srcPath and srcFiles to
destPath. If srcFiles contains exactly one file name,
destFile is used as the destination file name.
|
validateCreate | public String validateCreate(String srcPath, String srcFile, boolean isDir)(Code) | | Validates whether the files specified by srcPath and
srcFile can be created. A file may not be created in some
circumstances: if the file exists and is a directory, it cannot be
overwritten; if the file exists and is a normal file, it cannot be
overwritten by a directory. Returns null if the create is valid.
A VALIDATE_ (e.g.
FileManager.VALIDATE_CANTOVERWRITE ) error code is
returned if the create is invalid. Note that these error codes are
designed to be used as a key in a resource bundle.
|
validateMove | public String validateMove(String srcPath, String[] srcFiles, String destPath, String destFile)(Code) | | Validates moving srcFiles from srcPath to
destPath. srcFiles is expected to contain a list of
file names as Strings. If srcFiles contains a single
file name, destFile is validated as a destination file name.
Returns null if the move is valid. A VALIDATE_ (e.g.
FileManager.VALIDATE_INVALIDDESTPATH ) error code is returned if the move is
invalid. Note that these error codes are designed to be used as a key in
a resource bundle.
|
|
|