Top Description Fields Constructors Methods
org.apache.derby.impl.io.vfmem

public Class VirtualFile

extends Object
implements StorageFile
Class Inheritance
All Implemented Interfaces
org.apache.derby.io.StorageFile
Imports
java.io.FileNotFoundException, .InputStream, .OutputStream, org.apache.derby.shared.common.error.StandardException, org.apache.derby.io.StorageFile, .StorageRandomAccessFile

Represents a file in the virtual file system.

A virtual file is not created until one of the following methods are invoked:

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

Modifier and TypeField and Description
private final DataStore
dStore

The data store this virtual file belongs to.

private final String
path

The path of this virtual file.

Constructor Summary

AccessConstructor and Description
public
VirtualFile(String
the path of this virtual file
path
,
DataStore
the store this handle belongs to
dbData
)

Creates a new virtual file handle.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this file exists and can be written to, false otherwise.
canWrite
()

Implements org.apache.derby.io.StorageFile.canWrite.

Tells if this file can be written to.

public boolean

Returns:

true if the file was successfully created, false otherwise
createNewFile
()

Implements org.apache.derby.io.StorageFile.createNewFile.

Creates the the file denoted by this virtual file object.

public boolean

Returns:

true if this file exists and is successfully deleted, false otherwise.
delete
()

Implements org.apache.derby.io.StorageFile.delete.

Deletes this file, of if exists.

public boolean

Returns:

true if this file and all contents are successfully deleted, false otherwise.
deleteAll
()

Implements org.apache.derby.io.StorageFile.deleteAll.

Deletes the path denoted by this file and all its contents, including sub directories.

public boolean

Returns:

true if this file exists, false otherwise.
exists
()

Implements org.apache.derby.io.StorageFile.exists.

Tells if this file exists.

public String
getCanonicalPath()

Implements org.apache.derby.io.StorageFile.getCanonicalPath.

Converts this StorageFile into a canonical pathname string.

private DataStoreEntry

Returns:

The assoiciated DataStoreEntry if it exists, null if it doesn't exist.
getEntry
()

Returns the data store entry denoted by this file, if it exists.

public int
getExclusiveFileLock()

Implements org.apache.derby.io.StorageFile.getExclusiveFileLock.

Get an exclusive lock with this name.

public InputStream

Returns:

An InputStream instance.
getInputStream
()

Implements org.apache.derby.io.StorageFile.getInputStream.

Returns an input stream for the file denoted.

public String
public OutputStream

Returns:

An OutputStream-instance.
getOutputStream
()

Implements org.apache.derby.io.StorageFile.getOutputStream.

Obtains an output stream for the file denoted.

public OutputStream

Returns:

An OutputStream-instance.
getOutputStream
(boolean
tells if the file should be appended or truncated
append
)

Implements org.apache.derby.io.StorageFile.getOutputStream.

Obtains an output stream for the file denoted.

public StorageFile
getParentDir()

Implements org.apache.derby.io.StorageFile.getParentDir.

Get the name of the parent directory if this name includes a parent.

public String

Returns:

The path of this file.
getPath
()

Implements org.apache.derby.io.StorageFile.getPath.

Returns the path of this file.

public StorageRandomAccessFile

Returns:

A StorageRandomAccessFile-instance.
getRandomAccessFile
(String
file mode, one of "r", "rw", "rws" or "rwd" (lower-case letters are required)
mode
)

Implements org.apache.derby.io.StorageFile.getRandomAccessFile.

Creates a random access file that can be used to read and write from/into the file.

public boolean

Returns:

true if this file represents an existing directoy, false otherwise.
isDirectory
()

Implements org.apache.derby.io.StorageFile.isDirectory.

Tells if this file is a directory.

public long

Returns:

The length of the existing file, or 0 if the path denotes a directory or a non-existing file.
length
()

Returns the length of the file.

public void
public String[]

Returns:

A list of all files and directories, or null if this file doesn't denote a directory or doesn't exist.
list
()

Implements org.apache.derby.io.StorageFile.list.

Returns the contents of the directory denoted by this file, including any sub directories and their contents.

public boolean

Returns:

true if the directory was created, false otherwise.
mkdir
()

Implements org.apache.derby.io.StorageFile.mkdir.

Creates the directory denoted by this virtual file if it doesn't exist.

public boolean

Returns:

true if the directory was created, false otherwise.
mkdirs
()

Implements org.apache.derby.io.StorageFile.mkdirs.

Creates the directory and any parent directories denoted by this virtual file.

public void
releaseExclusiveFileLock()

Implements org.apache.derby.io.StorageFile.releaseExclusiveFileLock.

Release the resource associated with an earlier acquired exclusive lock releaseExclusiveFileLock() may delete the file

public boolean

Returns:

true if the fail was renamed, false otherwise
renameTo
(StorageFile
the new name
newName
)

Implements org.apache.derby.io.StorageFile.renameTo.

Renames the file denoted by this handle.

public boolean
setReadOnly()

Implements org.apache.derby.io.StorageFile.setReadOnly.

Make the named file or directory read-only.

public String

Returns:

Textual representation.
toString
()

Overrides java.lang.Object.toString.

Returns a textual representation of this file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

dStoreback to summary
private final DataStore dStore

The data store this virtual file belongs to.

pathback to summary
private final String path

The path of this virtual file.

Constructor Detail

VirtualFileback to summary
public VirtualFile(String path, DataStore dbData)

Creates a new virtual file handle.

Parameters
path:String

the path of this virtual file

dbData:DataStore

the store this handle belongs to

Method Detail

canWriteback to summary
public boolean canWrite()

Implements org.apache.derby.io.StorageFile.canWrite.

Tells if this file can be written to.

Returns:boolean

true if this file exists and can be written to, false otherwise.

createNewFileback to summary
public boolean createNewFile()

Implements org.apache.derby.io.StorageFile.createNewFile.

Creates the the file denoted by this virtual file object.

Returns:boolean

true if the file was successfully created, false otherwise

deleteback to summary
public boolean delete()

Implements org.apache.derby.io.StorageFile.delete.

Deletes this file, of if exists.

Returns:boolean

true if this file exists and is successfully deleted, false otherwise.

deleteAllback to summary
public boolean deleteAll()

Implements org.apache.derby.io.StorageFile.deleteAll.

Deletes the path denoted by this file and all its contents, including sub directories.

Returns:boolean

true if this file and all contents are successfully deleted, false otherwise.

existsback to summary
public boolean exists()

Implements org.apache.derby.io.StorageFile.exists.

Tells if this file exists.

Returns:boolean

true if this file exists, false otherwise.

getCanonicalPathback to summary
public String getCanonicalPath()

Implements org.apache.derby.io.StorageFile.getCanonicalPath.

Doc from org.apache.derby.io.StorageFile.getCanonicalPath.

Converts this StorageFile into a canonical pathname string. The form of the canonical path is system dependent.

Returns:String

The pathname as a string.

getEntryback to summary
private DataStoreEntry getEntry()

Returns the data store entry denoted by this file, if it exists.

Returns:DataStoreEntry

The assoiciated DataStoreEntry if it exists, null if it doesn't exist.

getExclusiveFileLockback to summary
public int getExclusiveFileLock() throws StandardException

Implements org.apache.derby.io.StorageFile.getExclusiveFileLock.

Doc from org.apache.derby.io.StorageFile.getExclusiveFileLock.

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.

Returns:int

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.

getInputStreamback to summary
public InputStream getInputStream() throws FileNotFoundException

Implements org.apache.derby.io.StorageFile.getInputStream.

Returns an input stream for the file denoted.

Returns:InputStream

An InputStream instance.

Exceptions
FileNotFoundException:
if the file doesn't exists or it is a directory
getNameback to summary
public String getName()

Implements org.apache.derby.io.StorageFile.getName.

Returns:String

Doc from org.apache.derby.io.StorageFile.getName.

The last segment in the path name, "" if the path name sequence is empty.

getOutputStreamback to summary
public OutputStream getOutputStream() throws FileNotFoundException

Implements org.apache.derby.io.StorageFile.getOutputStream.

Obtains an output stream for the file denoted.

If the file already exists, it will be truncated.

Returns:OutputStream

An OutputStream-instance.

Exceptions
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 file
getOutputStreamback to summary
public OutputStream getOutputStream(boolean append) throws FileNotFoundException

Implements org.apache.derby.io.StorageFile.getOutputStream.

Obtains an output stream for the file denoted.

Parameters
append:boolean

tells if the file should be appended or truncated

Returns:OutputStream

An OutputStream-instance.

Exceptions
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 file
getParentDirback to summary
public StorageFile getParentDir()

Implements org.apache.derby.io.StorageFile.getParentDir.

Doc from org.apache.derby.io.StorageFile.getParentDir.

Get the name of the parent directory if this name includes a parent.

Returns:StorageFile

An StorageFile denoting the parent directory of this StorageFile, if it has a parent, null if it does not have a parent.

getPathback to summary
public String getPath()

Implements org.apache.derby.io.StorageFile.getPath.

Returns the path of this file.

Returns:String

The path of this file.

getRandomAccessFileback to summary
public StorageRandomAccessFile getRandomAccessFile(String mode) throws FileNotFoundException

Implements org.apache.derby.io.StorageFile.getRandomAccessFile.

Creates a random access file that can be used to read and write from/into the file.

Parameters
mode:String

file mode, one of "r", "rw", "rws" or "rwd" (lower-case letters are required)

Returns:StorageRandomAccessFile

A StorageRandomAccessFile-instance.

Exceptions
FileNotFoundException:
if the file denoted is a directory,
IllegalArgumentException:
if the specificed mode is invalid
isDirectoryback to summary
public boolean isDirectory()

Implements org.apache.derby.io.StorageFile.isDirectory.

Tells if this file is a directory.

Note that false is returned if this path doesn't exist.

Returns:boolean

true if this file represents an existing directoy, false otherwise.

lengthback to summary
public long length()

Returns the length of the file.

If the file doesn't exists, or is a directory, 0 is returned.

Returns:long

The length of the existing file, or 0 if the path denotes a directory or a non-existing file.

limitAccessToOwnerback to summary
public void limitAccessToOwner()

Implements org.apache.derby.io.StorageFile.limitAccessToOwner.

Doc from org.apache.derby.io.StorageFile.limitAccessToOwner.

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 property derby.useDefaultFilePermissions is set to true.

listback to summary
public String[] list()

Implements org.apache.derby.io.StorageFile.list.

Returns the contents of the directory denoted by this file, including any sub directories and their contents.

Returns:String[]

A list of all files and directories, or null if this file doesn't denote a directory or doesn't exist.

mkdirback to summary
public boolean mkdir()

Implements org.apache.derby.io.StorageFile.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.

Returns:boolean

true if the directory was created, false otherwise.

mkdirsback to summary
public boolean mkdirs()

Implements org.apache.derby.io.StorageFile.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.

Returns:boolean

true if the directory was created, false otherwise.

releaseExclusiveFileLockback to summary
public void releaseExclusiveFileLock()

Implements org.apache.derby.io.StorageFile.releaseExclusiveFileLock.

Doc from org.apache.derby.io.StorageFile.releaseExclusiveFileLock.

Release the resource associated with an earlier acquired exclusive lock releaseExclusiveFileLock() may delete the file

renameToback to summary
public boolean renameTo(StorageFile newName)

Implements org.apache.derby.io.StorageFile.renameTo.

Renames the file denoted by this handle.

Parameters
newName:StorageFile

the new name

Returns:boolean

true if the fail was renamed, false otherwise

setReadOnlyback to summary
public boolean setReadOnly()

Implements org.apache.derby.io.StorageFile.setReadOnly.

Doc from org.apache.derby.io.StorageFile.setReadOnly.

Make the named file or directory read-only. This interface does not specify whether this also makes the file undeletable.

Returns:boolean

true if the named file or directory was made read-only, or it already was read-only; false if not.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a textual representation of this file.

Returns:String

Textual representation.