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:
createNewFilegetOutputStreamgetRandomAccessFilemkdirmkdirs
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 DataStoreThe data store this virtual file belongs to.private final StringThe path of this virtual file.Fields inherited from interface 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 TypeMethodDescriptionbooleancanWrite()Tells if this file can be written to.booleanCreates the the file denoted by this virtual file object.booleandelete()Deletes this file, of if exists.booleanDeletes the path denoted by this file and all its contents, including sub directories.booleanexists()Tells if this file exists.Converts this StorageFile into a canonical pathname string.private DataStoreEntrygetEntry()Returns the data store entry denoted by this file, if it exists.intGet 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.booleanTells if this file is a directory.longlength()Returns the length of the file.voidUse when creating a new file.String[]list()Returns the contents of the directory denoted by this file, including any sub directories and their contents.booleanmkdir()Creates the directory denoted by this virtual file if it doesn't exist.booleanmkdirs()Creates the directory and any parent directories denoted by this virtual file.voidRelease the resource associated with an earlier acquired exclusive lock releaseExclusiveFileLock() may delete the filebooleanrenameTo(StorageFile newName) Renames the file denoted by this handle.booleanMake 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
-
-
Method Details
-
list
Returns the contents of the directory denoted by this file, including any sub directories and their contents.- Specified by:
listin interfaceStorageFile- Returns:
- A list of all files and directories, or
nullif 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:
canWritein interfaceStorageFile- Returns:
trueif this file exists and can be written to,falseotherwise.
-
exists
public boolean exists()Tells if this file exists.- Specified by:
existsin interfaceStorageFile- Returns:
trueif this file exists,falseotherwise.
-
isDirectory
public boolean isDirectory()Tells if this file is a directory.Note that
falseis returned if this path doesn't exist.- Specified by:
isDirectoryin interfaceStorageFile- Returns:
trueif this file represents an existing directoy,falseotherwise.
-
delete
public boolean delete()Deletes this file, of if exists.- Specified by:
deletein interfaceStorageFile- Returns:
trueif this file exists and is successfully deleted,falseotherwise.
-
deleteAll
public boolean deleteAll()Deletes the path denoted by this file and all its contents, including sub directories.- Specified by:
deleteAllin interfaceStorageFile- Returns:
trueif this file and all contents are successfully deleted,falseotherwise.
-
getPath
Returns the path of this file.- Specified by:
getPathin interfaceStorageFile- Returns:
- The path of this file.
- See Also:
-
getCanonicalPath
Description copied from interface:StorageFileConverts this StorageFile into a canonical pathname string. The form of the canonical path is system dependent.- Specified by:
getCanonicalPathin interfaceStorageFile- Returns:
- The pathname as a string.
-
getName
- Specified by:
getNamein 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:
createNewFilein interfaceStorageFile- Returns:
trueif the file was successfully created,falseotherwise
-
renameTo
Renames the file denoted by this handle.- Specified by:
renameToin interfaceStorageFile- Parameters:
newName- the new name- Returns:
trueif the fail was renamed,falseotherwise
-
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:
mkdirin interfaceStorageFile- Returns:
trueif the directory was created,falseotherwise.
-
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:
mkdirsin interfaceStorageFile- Returns:
trueif the directory was created,falseotherwise.
-
length
public long length()Returns the length of the file.If the file doesn't exists, or is a directory,
0is returned.- Returns:
- The length of the existing file, or
0if the path denotes a directory or a non-existing file.
-
getParentDir
Description copied from interface:StorageFileGet the name of the parent directory if this name includes a parent.- Specified by:
getParentDirin 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:StorageFileMake the named file or directory read-only. This interface does not specify whether this also makes the file undeletable.- Specified by:
setReadOnlyin 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:
getOutputStreamin 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 anOutputStreamcannot be created for the file
-
getOutputStream
Obtains an output stream for the file denoted.- Specified by:
getOutputStreamin 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 anOutputStreamcannot be created for the file
-
getInputStream
Returns an input stream for the file denoted.- Specified by:
getInputStreamin interfaceStorageFile- Returns:
- An
InputStreaminstance. - Throws:
FileNotFoundException- if the file doesn't exists or it is a directory
-
getExclusiveFileLock
Description copied from interface:StorageFileGet 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:
getExclusiveFileLockin 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:StorageFileRelease the resource associated with an earlier acquired exclusive lock releaseExclusiveFileLock() may delete the file- Specified by:
releaseExclusiveFileLockin interfaceStorageFile- See Also:
-
getRandomAccessFile
Creates a random access file that can be used to read and write from/into the file.- Specified by:
getRandomAccessFilein 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
-
getEntry
Returns the data store entry denoted by this file, if it exists.- Returns:
- The assoiciated
DataStoreEntryif it exists,nullif it doesn't exist.
-
limitAccessToOwner
public void limitAccessToOwner()Description copied from interface:StorageFileUse 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.useDefaultFilePermissionsis set totrue.- Specified by:
limitAccessToOwnerin interfaceStorageFile
-