| org.apache.derby.io.StorageFile
All known Subclasses: org.apache.derbyTesting.functionTests.util.corruptio.CorruptFile, org.apache.derby.impl.io.DirFile, org.apache.derby.impl.io.InputStreamFile,
StorageFile | public interface StorageFile (Code) | | This interface abstracts file naming. Any method in this interface
that also appears in the java.io.File class should behave as the java.io.File method does.
When used by the database engine all files will be under either the database
directory, specified by the databaseName argument of the
StorageFactory.init StorageFactory.init method, or under the temporary file
directory returned by the
StorageFactory.getTempDirStorageFactory.getTempDir method. All relative path names are relative to
the database directory.
The database engine will call this interface's methods from its own privilege blocks.
Different threads may operate on the same underlying file at the same time, either through the
same or different StorageFile objects. The StiFile implementation must be capable of handling this.
See Also: java.io.File |
Method Summary | |
public boolean | canWrite() Determine whether the named file is writable. | public boolean | createNewFile() If the named file does not already exist then create it as an empty normal file.
The implementation
must synchronize with other threads accessing the same file (in the same or a different process).
If two threads both attempt to create a file with the same name
at the same time then at most one should succeed.
true if this thread's invocation of createNewFile successfully created the named file;false if not, i.e. | public boolean | delete() Deletes the named file or empty directory. | public boolean | deleteAll() Deletes the named file and, if it is a directory, all the files and directories it contains. | public boolean | exists() Tests whether the named file exists. | public String | getCanonicalPath() Converts this StorageFile into a canonical pathname string. | public int | getExclusiveFileLock() Get an exclusive lock with this name. | public InputStream | getInputStream() Creates an input stream from a file name. | public String | getName() | public OutputStream | getOutputStream() Creates an output stream from a file name. | public OutputStream | getOutputStream(boolean append) Creates an output stream from a file name.
Parameters: append - If true then data will be appended to the end of the file, if it already exists.If false and a normal file already exists with this name the file will first be truncatedto zero length. | public StorageFile | getParentDir() Get the name of the parent directory if this name includes a parent. | public String | getPath() Converts this StorageFile into a pathname string. | public StorageRandomAccessFile | getRandomAccessFile(String mode) Get a random access file.
This method is not called if the StorageFactory is read only. | public URL | getURL() Get a URL representing this file. | public boolean | isDirectory() Tests whether the named file is a directory, or not. | public long | length() Returns the length of the named file if it is not a directory. | public String[] | list() Get the names of all files and sub-directories in the directory named by this path name.
This method is only used in a writable database.
An array of the names of the files and directories in thisdirectory denoted by this abstract pathname. | public boolean | mkdir() Creates the named directory. | public boolean | mkdirs() Creates the named directory, and all nonexistent parent directories. | public void | releaseExclusiveFileLock() | public boolean | renameTo(StorageFile newName) Rename the file denoted by this name. | public boolean | setReadOnly() Make the named file or directory read-only. |
EXCLUSIVE_FILE_LOCK | final public static int EXCLUSIVE_FILE_LOCK(Code) | | |
EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE | final public static int EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE(Code) | | |
NO_FILE_LOCK_SUPPORT | final public static int NO_FILE_LOCK_SUPPORT(Code) | | |
canWrite | public boolean canWrite()(Code) | | Determine whether the named file is writable.
true if the file exists and is writable, false if not. |
createNewFile | public boolean createNewFile() throws IOException(Code) | | If the named file does not already exist then create it as an empty normal file.
The implementation
must synchronize with other threads accessing the same file (in the same or a different process).
If two threads both attempt to create a file with the same name
at the same time then at most one should succeed.
true if this thread's invocation of createNewFile successfully created the named file;false if not, i.e. false if the named file already exists or if another concurrent thread created it. exception: IOException - - If the directory does not exist or some other I/O error occurred |
delete | public boolean delete()(Code) | | Deletes the named file or empty directory. This method does not delete non-empty directories.
true if the named file or directory is successfully deleted, false if not |
deleteAll | public boolean deleteAll()(Code) | | Deletes the named file and, if it is a directory, all the files and directories it contains.
true if the named file or directory is successfully deleted, false if not |
exists | public boolean exists()(Code) | | Tests whether the named file exists.
true if the named file exists, false if not. |
getCanonicalPath | public String getCanonicalPath() throws IOException(Code) | | Converts this StorageFile into a canonical pathname string. The form of the canonical path is system dependent.
The pathname as a string. exception: IOException - if an I/O error occurred while finding the canonical name |
getExclusiveFileLock | public int getExclusiveFileLock()(Code) | | Get an exclusive lock with this name. This is used to ensure that two or more JVMs do not open the same database
at the same time.
EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE if the lock cannot be acquired because it is already held. EXCLUSIVE_FILE_LOCK if the lock was successfully acquired. NO_FILE_LOCK_SUPPORT if the system does not support exclusive locks.
|
getName | public String getName()(Code) | | The last segment in the path name, "" if the path name sequence is empty. |
getOutputStream | public OutputStream getOutputStream() throws FileNotFoundException(Code) | | Creates an output stream from a file name. If a normal file already exists with this name it
will first be truncated to zero length.
an output stream suitable for writing to the file. exception: FileNotFoundException - if the file exists but is a directoryrather than a regular file, does not exist but cannot be created, orcannot be opened for any other reason. |
getOutputStream | public OutputStream getOutputStream(boolean append) throws FileNotFoundException(Code) | | Creates an output stream from a file name.
Parameters: append - If true then data will be appended to the end of the file, if it already exists.If false and a normal file already exists with this name the file will first be truncatedto zero length. an output stream suitable for writing to the file. exception: FileNotFoundException - if the file exists but is a directoryrather than a regular file, does not exist but cannot be created, orcannot be opened for any other reason. |
getParentDir | public StorageFile getParentDir()(Code) | | Get the name of the parent directory if this name includes a parent.
An StorageFile denoting the parent directory of this StorageFile, if it has a parent, null ifit does not have a parent. |
getPath | public String getPath()(Code) | | Converts this StorageFile into a pathname string. The character returned by StorageFactory.getSeparator()
is used to separate the directory and file names in the sequence.
The returned path may include the database directory. Therefore it cannot be directly used to make an StorageFile
equivalent to this one.
The pathname as a string. See Also: StorageFactory.getSeparator |
getRandomAccessFile | public StorageRandomAccessFile getRandomAccessFile(String mode) throws FileNotFoundException(Code) | | Get a random access file.
This method is not called if the StorageFactory is read only. It is unspecified if the StorageFactory
that created it is not a WritableStorageFactory.
Parameters: mode - "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specifythat the data is to be written to persistent store, consistent with thejava.io.RandomAccessFile class ("synchronized" with the persistentstorage, in the file system meaning of the word "synchronized"). Howeverthe implementation is not required to implement the "rws" or "rwd"modes. If the "rws" andr "rwd" modes are supported then the supportsRws() methodof the StorageFactory returns true. If supportsRws() returns false then theimplementation may treat "rws" and "rwd" as "rw". It is up tothe user of this interface to call the StorageRandomAccessFile.syncmethod if necessary. However, if the "rws" or "rwd" modes are supported and theRandomAccessFile was opened in "rws" or "rwd" mode then theimplementation of StorageRandomAccessFile.sync need not do anything. an object that can be used for random access to the file. exception: IllegalArgumentException - if the mode argument is not equal to one of "r", "rw", "rws", or "rwd". exception: FileNotFoundException - if the file exists but is a directory rather than a regularfile, or cannot be opened or created for any other reason . See Also: java.io.RandomAccessFile |
getURL | public URL getURL() throws MalformedURLException(Code) | | Get a URL representing this file. A valid URL does not indicate the file exists,
it may just be a URL that will fail on opening. Some implementations
return null if the file does not exist.
throws: MalformedURLException - File cannot be represented as a URL. |
isDirectory | public boolean isDirectory()(Code) | | Tests whether the named file is a directory, or not. This is only called in writable storage factories.
true if named file exists and is a directory, false if not.The return value is undefined if the storage is read-only. |
length | public long length()(Code) | | Returns the length of the named file if it is not a directory. The return value is not specified
if the file is a directory.
The length, in bytes, of the named file if it exists and is not a directory,0 if the file does not exist, or any value if the named file is a directory. |
list | public String[] list()(Code) | | Get the names of all files and sub-directories in the directory named by this path name.
This method is only used in a writable database.
An array of the names of the files and directories in thisdirectory denoted by this abstract pathname. The returned array will have length 0if this directory is empty. Returns null if this StorageFile is not a directory, orif an I/O error occurs. The return value is undefined if the database is read-only. |
mkdir | public boolean mkdir()(Code) | | Creates the named directory.
true if the directory was created; false if not. |
mkdirs | public boolean mkdirs()(Code) | | Creates the named directory, and all nonexistent parent directories.
true if the directory was created, false if not |
renameTo | public boolean renameTo(StorageFile newName)(Code) | | Rename the file denoted by this name. Note that StorageFile objects are immutable. This method
renames the underlying file, it does not change this StorageFile object. The StorageFile object denotes the
same name as before, however the exists() method will return false after the renameTo method
executes successfully.
It is not specified whether this method will succeed if a file already exists under the new name.
Parameters: newName - the new name. true if the rename succeeded, false if not. |
setReadOnly | public boolean setReadOnly()(Code) | | Make the named file or directory read-only. This interface does not specify whether this
also makes the file undeletable.
true if the named file or directory was made read-only, or it already was read-only;false if not. |
|
|