StorageFilepublic class VirtualFile extends java.lang.Object implements StorageFile
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.
| Modifier and Type | Field | Description |
|---|---|---|
private DataStore |
dStore |
The data store this virtual file belongs to.
|
private java.lang.String |
path |
The path of this virtual file.
|
EXCLUSIVE_FILE_LOCK, EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE, NO_FILE_LOCK_SUPPORT| Constructor | Description |
|---|---|
VirtualFile(java.lang.String path,
DataStore dbData) |
Creates a new virtual file handle.
|
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
canWrite() |
Tells if this file can be written to.
|
boolean |
createNewFile() |
Creates the the file denoted by this virtual file object.
|
boolean |
delete() |
Deletes this file, of if exists.
|
boolean |
deleteAll() |
Deletes the path denoted by this file and all its contents, including
sub directories.
|
boolean |
exists() |
Tells if this file exists.
|
java.lang.String |
getCanonicalPath() |
Converts this StorageFile into a canonical pathname string.
|
private DataStoreEntry |
getEntry() |
Returns the data store entry denoted by this file, if it exists.
|
int |
getExclusiveFileLock() |
Get an exclusive lock with this name.
|
java.io.InputStream |
getInputStream() |
Returns an input stream for the file denoted.
|
java.lang.String |
getName() |
|
java.io.OutputStream |
getOutputStream() |
Obtains an output stream for the file denoted.
|
java.io.OutputStream |
getOutputStream(boolean append) |
Obtains an output stream for the file denoted.
|
StorageFile |
getParentDir() |
Get the name of the parent directory if this name includes a parent.
|
java.lang.String |
getPath() |
Returns the path of this file.
|
StorageRandomAccessFile |
getRandomAccessFile(java.lang.String mode) |
Creates a random access file that can be used to read and write
from/into the file.
|
boolean |
isDirectory() |
Tells if this file is a directory.
|
long |
length() |
Returns the length of the file.
|
void |
limitAccessToOwner() |
Use when creating a new file.
|
java.lang.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 |
releaseExclusiveFileLock() |
Release the resource associated with an earlier acquired exclusive lock
releaseExclusiveFileLock() may delete the file
|
boolean |
renameTo(StorageFile newName) |
Renames the file denoted by this handle.
|
boolean |
setReadOnly() |
Make the named file or directory read-only.
|
java.lang.String |
toString() |
Returns a textual representation of this file.
|
private final java.lang.String path
private final DataStore dStore
public VirtualFile(java.lang.String path,
DataStore dbData)
path - the path of this virtual filedbData - the store this handle belongs topublic java.lang.String[] list()
list in interface StorageFilenull if this file
doesn't denote a directory or doesn't exist.public boolean canWrite()
canWrite in interface StorageFiletrue if this file exists and can be written to,
false otherwise.public boolean exists()
exists in interface StorageFiletrue if this file exists, false otherwise.public boolean isDirectory()
Note that false is returned if this path doesn't exist.
isDirectory in interface StorageFiletrue if this file represents an existing directoy,
false otherwise.public boolean delete()
delete in interface StorageFiletrue if this file exists and is successfully deleted,
false otherwise.public boolean deleteAll()
deleteAll in interface StorageFiletrue if this file and all contents are successfully
deleted, false otherwise.public java.lang.String getPath()
getPath in interface StorageFileStorageFactory.getSeparator()public java.lang.String getCanonicalPath()
StorageFilegetCanonicalPath in interface StorageFilepublic java.lang.String getName()
getName in interface StorageFilepublic boolean createNewFile()
createNewFile in interface StorageFiletrue if the file was successfully created, false
otherwisepublic boolean renameTo(StorageFile newName)
renameTo in interface StorageFilenewName - the new nametrue if the fail was renamed, false otherwisepublic boolean mkdir()
For the directory to be created, it cannot exist already (either as a file or a directory), and any parent directories must exist.
mkdir in interface StorageFiletrue if the directory was created, false
otherwise.public boolean mkdirs()
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.
mkdirs in interface StorageFiletrue if the directory was created, false
otherwise.public long length()
If the file doesn't exists, or is a directory, 0 is returned.
0 if the path denotes
a directory or a non-existing file.public StorageFile getParentDir()
StorageFilegetParentDir in interface StorageFilepublic boolean setReadOnly()
StorageFilesetReadOnly in interface StorageFilepublic java.io.OutputStream getOutputStream()
throws java.io.FileNotFoundException
If the file already exists, it will be truncated.
getOutputStream in interface StorageFileOutputStream-instance.java.io.FileNotFoundException - if the denoted path is a directory, the
file is read-only, the file cannot be created or any other reason
why an OutputStream cannot be created for the filepublic java.io.OutputStream getOutputStream(boolean append)
throws java.io.FileNotFoundException
getOutputStream in interface StorageFileappend - tells if the file should be appended or truncatedOutputStream-instance.java.io.FileNotFoundException - if the denoted path is a directory, the
file is read-only, the file cannot be created or any other reason
why an OutputStream cannot be created for the filepublic java.io.InputStream getInputStream()
throws java.io.FileNotFoundException
getInputStream in interface StorageFileInputStream instance.java.io.FileNotFoundException - if the file doesn't exists or it is a
directorypublic int getExclusiveFileLock()
throws StandardException
StorageFilegetExclusiveFileLock in interface StorageFileStandardExceptionpublic void releaseExclusiveFileLock()
StorageFilereleaseExclusiveFileLock in interface StorageFileStorageFile.getExclusiveFileLock()public StorageRandomAccessFile getRandomAccessFile(java.lang.String mode) throws java.io.FileNotFoundException
getRandomAccessFile in interface StorageFilemode - file mode, one of "r", "rw", "rws" or "rwd" (lower-case
letters are required)StorageRandomAccessFile-instance.java.lang.IllegalArgumentException - if the specificed mode is invalidjava.io.FileNotFoundException - if the file denoted is a directory,public java.lang.String toString()
toString in class java.lang.Objectprivate DataStoreEntry getEntry()
DataStoreEntry if it exists,
null if it doesn't exist.public void limitAccessToOwner()
StorageFile
derby.useDefaultFilePermissions is set to true.limitAccessToOwner in interface StorageFileApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.