Package org.apache.derby.impl.io.vfmem
Class VirtualFile
java.lang.Object
org.apache.derby.impl.io.vfmem.VirtualFile
- All Implemented Interfaces:
StorageFile
Represents a file in the virtual file system.
A virtual file is not created until one of the following methods are invoked:
createNewFile
getOutputStream
getRandomAccessFile
mkdir
mkdirs
When a method that requires access to the file data or to know if the file exists or not, the associated data store is consulted.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DataStore
The data store this virtual file belongs to.private final String
The path of this virtual file.Fields inherited from interface org.apache.derby.io.StorageFile
EXCLUSIVE_FILE_LOCK, EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE, NO_FILE_LOCK_SUPPORT
-
Constructor Summary
ConstructorsConstructorDescriptionVirtualFile
(String path, DataStore dbData) Creates a new virtual file handle. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canWrite()
Tells if this file can be written to.boolean
Creates the the file denoted by this virtual file object.boolean
delete()
Deletes this file, of if exists.boolean
Deletes the path denoted by this file and all its contents, including sub directories.boolean
exists()
Tells if this file exists.Converts this StorageFile into a canonical pathname string.private DataStoreEntry
getEntry()
Returns the data store entry denoted by this file, if it exists.int
Get an exclusive lock with this name.Returns an input stream for the file denoted.getName()
Obtains an output stream for the file denoted.getOutputStream
(boolean append) Obtains an output stream for the file denoted.Get the name of the parent directory if this name includes a parent.getPath()
Returns the path of this file.getRandomAccessFile
(String mode) Creates a random access file that can be used to read and write from/into the file.boolean
Tells if this file is a directory.long
length()
Returns the length of the file.void
Use when creating a new file.String[]
list()
Returns the contents of the directory denoted by this file, including any sub directories and their contents.boolean
mkdir()
Creates the directory denoted by this virtual file if it doesn't exist.boolean
mkdirs()
Creates the directory and any parent directories denoted by this virtual file.void
Release the resource associated with an earlier acquired exclusive lock releaseExclusiveFileLock() may delete the fileboolean
renameTo
(StorageFile newName) Renames the file denoted by this handle.boolean
Make the named file or directory read-only.toString()
Returns a textual representation of this file.
-
Field Details
-
path
The path of this virtual file. -
dStore
The data store this virtual file belongs to.
-
-
Constructor Details
-
VirtualFile
Creates a new virtual file handle.- Parameters:
path
- the path of this virtual filedbData
- the store this handle belongs to
-
-
Method Details
-
list
Returns the contents of the directory denoted by this file, including any sub directories and their contents.- Specified by:
list
in interfaceStorageFile
- Returns:
- A list of all files and directories, or
null
if this file doesn't denote a directory or doesn't exist.
-
canWrite
public boolean canWrite()Tells if this file can be written to.- Specified by:
canWrite
in interfaceStorageFile
- Returns:
true
if this file exists and can be written to,false
otherwise.
-
exists
public boolean exists()Tells if this file exists.- Specified by:
exists
in interfaceStorageFile
- Returns:
true
if this file exists,false
otherwise.
-
isDirectory
public boolean isDirectory()Tells if this file is a directory.Note that
false
is returned if this path doesn't exist.- Specified by:
isDirectory
in interfaceStorageFile
- Returns:
true
if this file represents an existing directoy,false
otherwise.
-
delete
public boolean delete()Deletes this file, of if exists.- Specified by:
delete
in interfaceStorageFile
- Returns:
true
if this file exists and is successfully deleted,false
otherwise.
-
deleteAll
public boolean deleteAll()Deletes the path denoted by this file and all its contents, including sub directories.- Specified by:
deleteAll
in interfaceStorageFile
- Returns:
true
if this file and all contents are successfully deleted,false
otherwise.
-
getPath
Returns the path of this file.- Specified by:
getPath
in interfaceStorageFile
- Returns:
- The path of this file.
- See Also:
-
getCanonicalPath
Description copied from interface:StorageFile
Converts this StorageFile into a canonical pathname string. The form of the canonical path is system dependent.- Specified by:
getCanonicalPath
in interfaceStorageFile
- Returns:
- The pathname as a string.
-
getName
- Specified by:
getName
in interfaceStorageFile
- Returns:
- The last segment in the path name, "" if the path name sequence is empty.
-
createNewFile
public boolean createNewFile()Creates the the file denoted by this virtual file object.- Specified by:
createNewFile
in interfaceStorageFile
- Returns:
true
if the file was successfully created,false
otherwise
-
renameTo
Renames the file denoted by this handle.- Specified by:
renameTo
in interfaceStorageFile
- Parameters:
newName
- the new name- Returns:
true
if the fail was renamed,false
otherwise
-
mkdir
public boolean mkdir()Creates the directory denoted by this virtual file if it doesn't exist.For the directory to be created, it cannot exist already (either as a file or a directory), and any parent directories must exist.
- Specified by:
mkdir
in interfaceStorageFile
- Returns:
true
if the directory was created,false
otherwise.
-
mkdirs
public boolean mkdirs()Creates the directory and any parent directories denoted by this virtual file.For the directory to be created, it cannot exist already (either as a file or a directory), and all the parent elements most denote either existing directories or non-existing paths.
- Specified by:
mkdirs
in interfaceStorageFile
- Returns:
true
if the directory was created,false
otherwise.
-
length
public long length()Returns the length of the file.If the file doesn't exists, or is a directory,
0
is returned.- Returns:
- The length of the existing file, or
0
if the path denotes a directory or a non-existing file.
-
getParentDir
Description copied from interface:StorageFile
Get the name of the parent directory if this name includes a parent.- Specified by:
getParentDir
in interfaceStorageFile
- Returns:
- An StorageFile denoting the parent directory of this StorageFile, if it has a parent, null if it does not have a parent.
-
setReadOnly
public boolean setReadOnly()Description copied from interface:StorageFile
Make the named file or directory read-only. This interface does not specify whether this also makes the file undeletable.- Specified by:
setReadOnly
in interfaceStorageFile
- Returns:
- true if the named file or directory was made read-only, or it already was read-only; false if not.
-
getOutputStream
Obtains an output stream for the file denoted.If the file already exists, it will be truncated.
- Specified by:
getOutputStream
in interfaceStorageFile
- Returns:
- An
OutputStream
-instance. - Throws:
FileNotFoundException
- if the denoted path is a directory, the file is read-only, the file cannot be created or any other reason why anOutputStream
cannot be created for the file
-
getOutputStream
Obtains an output stream for the file denoted.- Specified by:
getOutputStream
in interfaceStorageFile
- Parameters:
append
- tells if the file should be appended or truncated- Returns:
- An
OutputStream
-instance. - Throws:
FileNotFoundException
- if the denoted path is a directory, the file is read-only, the file cannot be created or any other reason why anOutputStream
cannot be created for the file
-
getInputStream
Returns an input stream for the file denoted.- Specified by:
getInputStream
in interfaceStorageFile
- Returns:
- An
InputStream
instance. - Throws:
FileNotFoundException
- if the file doesn't exists or it is a directory
-
getExclusiveFileLock
Description copied from interface:StorageFile
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. ny StorageFile that has getExclusiveFileLock() called on it is not intended to be read from or written to. It's sole purpose is to provide a locked entity to avoid multiple instances of Derby accessing the same database. getExclusiveFileLock() may delete or overwrite any existing file.- Specified by:
getExclusiveFileLock
in interfaceStorageFile
- Returns:
- 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. - Throws:
StandardException
-
releaseExclusiveFileLock
public void releaseExclusiveFileLock()Description copied from interface:StorageFile
Release the resource associated with an earlier acquired exclusive lock releaseExclusiveFileLock() may delete the file- Specified by:
releaseExclusiveFileLock
in interfaceStorageFile
- See Also:
-
getRandomAccessFile
Creates a random access file that can be used to read and write from/into the file.- Specified by:
getRandomAccessFile
in interfaceStorageFile
- Parameters:
mode
- file mode, one of "r", "rw", "rws" or "rwd" (lower-case letters are required)- Returns:
- A
StorageRandomAccessFile
-instance. - Throws:
IllegalArgumentException
- if the specificed mode is invalidFileNotFoundException
- if the file denoted is a directory,- See Also:
-
toString
Returns a textual representation of this file. -
getEntry
Returns the data store entry denoted by this file, if it exists.- Returns:
- The assoiciated
DataStoreEntry
if it exists,null
if it doesn't exist.
-
limitAccessToOwner
public void limitAccessToOwner()Description copied from interface:StorageFile
Use when creating a new file. By default, a file created in an underlying file system, if applicable, will have read and write access for the file owner unless the propertyderby.useDefaultFilePermissions
is set totrue
.- Specified by:
limitAccessToOwner
in interfaceStorageFile
-