| org.apache.commons.vfs.FileObject
All known Subclasses: org.apache.commons.vfs.provider.zip.ZipFileObject, org.apache.commons.vfs.provider.AbstractFileObject, org.apache.commons.vfs.impl.DecoratedFileObject, org.apache.commons.vfs.provider.local.LocalFile, org.apache.commons.vfs.provider.sftp.SftpFileObject, org.apache.commons.vfs.provider.compressed.CompressedFileFileObject, org.apache.commons.vfs.provider.url.UrlFileObject, org.apache.commons.vfs.provider.ram.RamFileObject, org.apache.commons.vfs.provider.tar.TarFileObject,
FileObject | public interface FileObject (Code) | | Represents a file, and is used to access the content and
structure of the file.
Files are arranged in a hierarchy. Each hierachy forms a
file system. A file system represents things like a local OS
file system, a windows share, an HTTP server, or the contents of a Zip file.
There are two types of files: Folders, which contain other files,
and normal files, which contain data, or content. A folder may
not have any content, and a normal file cannot contain other files.
File Naming
TODO - write this.
Reading and Writing a File
Reading and writing a file, and all other operations on the file's
content, is done using the
FileContent object returned
by
FileObject.getContent .
Creating and Deleting a File
A file is created using either
FileObject.createFolder ,
FileObject.createFile ,
or by writing to the file using one of the
FileContent methods.
A file is deleted using
FileObject.delete . Recursive deletion can be
done using
FileObject.delete(FileSelector) .
Finding Files
Other files in the same file system as this file can be found
using:
To find files in another file system, use a
FileSystemManager .
author: Adam Murdoch version: $Revision: 483899 $ $Date: 2006-12-08 01:47:09 -0800 (Fri, 08 Dec 2006) $ See Also: FileSystemManager See Also: FileContent See Also: FileName |
Method Summary | |
public boolean | canRenameTo(FileObject newfile) Queries the file if it is possible to rename it to newfile. | public void | close() Closes this file, and its content. | public void | copyFrom(FileObject srcFile, FileSelector selector) Copies another file, and all its descendents, to this file.
If this file does not exist, it is created. | public void | createFile() Creates this file, if it does not exist. | public void | createFolder() Creates this folder, if it does not exist. | public boolean | delete() Deletes this file. | public int | delete(FileSelector selector) Deletes all descendents of this file that match a selector. | public boolean | exists() Determines if this file exists. | public FileObject[] | findFiles(FileSelector selector) Finds the set of matching descendents of this file, in depthwise order.
Parameters: selector - The selector to use to select matching files. | public void | findFiles(FileSelector selector, boolean depthwise, List selected) Finds the set of matching descendents of this file.
Parameters: selector - the selector used to determine if the file should be selected Parameters: depthwise - controls the ordering in the list. | public FileObject | getChild(String name) Returns a child of this file. | public FileObject[] | getChildren() Lists the children of this file.
An array containing the children of this file. | public FileContent | getContent() Returns this file's content. | FileOperations | getFileOperations() | public FileSystem | getFileSystem() Returns the file system that contains this file. | public FileName | getName() Returns the name of this file. | public FileObject | getParent() Returns the folder that contains this file.
The folder that contains this file. | public FileType | getType() Returns this file's type.
One of the FileType constants. | public URL | getURL() Returns a URL representing this file. | public boolean | isAttached() | public boolean | isContentOpen() | public boolean | isHidden() Determines if this file is hidden. | public boolean | isReadable() Determines if this file can be read. | public boolean | isWriteable() Determines if this file can be written to. | public void | moveTo(FileObject destFile) Move this file. | public void | refresh() | public FileObject | resolveFile(String name, NameScope scope) Finds a file, relative to this file. | public FileObject | resolveFile(String path) Finds a file, relative to this file. |
canRenameTo | public boolean canRenameTo(FileObject newfile)(Code) | | Queries the file if it is possible to rename it to newfile.
Parameters: newfile - the new file(-name) true it this is the case |
close | public void close() throws FileSystemException(Code) | | Closes this file, and its content. This method is a hint to the
implementation that it can release any resources associated with
the file.
The file object can continue to be used after this method is called.
throws: FileSystemException - On error closing the file. See Also: FileContent.close |
copyFrom | public void copyFrom(FileObject srcFile, FileSelector selector) throws FileSystemException(Code) | | Copies another file, and all its descendents, to this file.
If this file does not exist, it is created. Its parent folder is also
created, if necessary. If this file does exist, it is deleted first.
This method is not transactional. If it fails and throws an
exception, this file will potentially only be partially copied.
Parameters: srcFile - The source file to copy. Parameters: selector - The selector to use to select which files to copy. throws: FileSystemException - If this file is read-only, or if the source file does not exist,or on error copying the file. |
createFile | public void createFile() throws FileSystemException(Code) | | Creates this file, if it does not exist. Also creates any ancestor
folders which do not exist. This method does nothing if the file
already exists and is a file.
throws: FileSystemException - If the file already exists with the wrong type, or the parentfolder is read-only, or on error creating this file or one ofits ancestors. |
createFolder | public void createFolder() throws FileSystemException(Code) | | Creates this folder, if it does not exist. Also creates any ancestor
folders which do not exist. This method does nothing if the folder
already exists.
throws: FileSystemException - If the folder already exists with the wrong type, or the parentfolder is read-only, or on error creating this folder or one ofits ancestors. |
delete | public boolean delete() throws FileSystemException(Code) | | Deletes this file. Does nothing if this file does not exist of if it is a
folder that has children. Does not delete any descendents of this file,
use
FileObject.delete(FileSelector) for that.
true if this object has been deleted throws: FileSystemException - If this file is a non-empty folder, or if this file is read-only,or on error deleteing this file. |
delete | public int delete(FileSelector selector) throws FileSystemException(Code) | | Deletes all descendents of this file that match a selector. Does
nothing if this file does not exist.
This method is not transactional. If it fails and throws an
exception, this file will potentially only be partially deleted.
Parameters: selector - The selector to use to select which files to delete. the number of deleted objects throws: FileSystemException - If this file or one of its descendents is read-only, or on errordeleting this file or one of its descendents. |
findFiles | public FileObject[] findFiles(FileSelector selector) throws FileSystemException(Code) | | Finds the set of matching descendents of this file, in depthwise order.
Parameters: selector - The selector to use to select matching files. The matching files. The files are returned in depthwise order(that is, a child appears in the list before its parent). |
findFiles | public void findFiles(FileSelector selector, boolean depthwise, List selected) throws FileSystemException(Code) | | Finds the set of matching descendents of this file.
Parameters: selector - the selector used to determine if the file should be selected Parameters: depthwise - controls the ordering in the list. e.g. deepest first Parameters: selected - container for selected files. list needs not to be empty. throws: FileSystemException - |
getChildren | public FileObject[] getChildren() throws FileSystemException(Code) | | Lists the children of this file.
An array containing the children of this file. The array isunordered. If the file does not have any children, a zero-lengtharray is returned. This method never returns null. throws: FileSystemException - If this file does not exist, or is not a folder, or on errorlisting this file's children. |
getContent | public FileContent getContent() throws FileSystemException(Code) | | Returns this file's content. The
FileContent returned by this
method can be used to read and write the content of the file.
This method can be called if the file does not exist, and
the returned
FileContent can be used to create the file
by writing its content.
This file's content. throws: FileSystemException - On error getting this file's content. |
getFileSystem | public FileSystem getFileSystem()(Code) | | Returns the file system that contains this file.
The file system. |
getParent | public FileObject getParent() throws FileSystemException(Code) | | Returns the folder that contains this file.
The folder that contains this file. Returns null if this file isthe root of a file system. throws: FileSystemException - On error finding the file's parent. |
isAttached | public boolean isAttached()(Code) | | check if the fileObject is attaced
|
isContentOpen | public boolean isContentOpen()(Code) | | check if someone reads/write to this file
|
isReadable | public boolean isReadable() throws FileSystemException(Code) | | Determines if this file can be read.
true if this file is readable, false if not. throws: FileSystemException - On error determining if this file exists. |
isWriteable | public boolean isWriteable() throws FileSystemException(Code) | | Determines if this file can be written to.
true if this file is writeable, false if not. throws: FileSystemException - On error determining if this file exists. |
moveTo | public void moveTo(FileObject destFile) throws FileSystemException(Code) | | Move this file.
If the destFile exists, it is deleted first
Parameters: destFile - the New filename. throws: FileSystemException - If this file is read-only, or if the source file does not exist,or on error copying the file. |
refresh | public void refresh() throws FileSystemException(Code) | | This will prepare the fileObject to get resynchronized with the underlaying filesystem if required
|
resolveFile | public FileObject resolveFile(String path) throws FileSystemException(Code) | | Finds a file, relative to this file. Equivalent to calling
resolveFile( path, NameScope.FILE_SYSTEM ) .
Parameters: path - The path of the file to locate. Can either be a relativepath or an absolute path. The file. throws: FileSystemException - On error parsing the path, or on error finding the file. |
|
|