org.apache.derby.impl.io.vfmem
Class VirtualFile

java.lang.Object
  extended by org.apache.derby.impl.io.vfmem.VirtualFile
All Implemented Interfaces:
StorageFile

public class VirtualFile
extends java.lang.Object
implements StorageFile

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 assoicated data store is consulted.


Field Summary
private  DataStore dStore
          The data store this virtual file belongs to.
private  java.lang.String path
          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
VirtualFile(java.lang.String path, DataStore dbData)
          Creates a new virtual file handle.
 
Method Summary
 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.
 java.net.URL getURL()
          Get a URL representing this file.
 boolean isDirectory()
          Tells if this file is a directory.
 long length()
          Returns the length of the 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

path

private final java.lang.String path
The path of this virtual file.


dStore

private final DataStore dStore
The data store this virtual file belongs to.

Constructor Detail

VirtualFile

public VirtualFile(java.lang.String path,
                   DataStore dbData)
Creates a new virtual file handle.

Parameters:
path - the path of this virtual file
dbData - the store this handle belongs to
Method Detail

list

public java.lang.String[] list()
Returns the contents of the directory denoted by this file, including any sub directories and their contents.

Specified by:
list in interface StorageFile
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 interface StorageFile
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 interface StorageFile
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 interface StorageFile
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 interface StorageFile
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 interface StorageFile
Returns:
true if this file and all contents are successfully deleted, false otherwise.

getPath

public java.lang.String getPath()
Returns the path of this file.

Specified by:
getPath in interface StorageFile
Returns:
The path of this file.
See Also:
StorageFactory.getSeparator()

getCanonicalPath

public java.lang.String 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 interface StorageFile
Returns:
The pathname as a string.

getName

public java.lang.String getName()
Specified by:
getName in interface StorageFile
Returns:
The last segment in the path name, "" if the path name sequence is empty.

getURL

public java.net.URL getURL()
                    throws java.net.MalformedURLException
Description copied from interface: StorageFile
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.

Specified by:
getURL in interface StorageFile
Throws:
java.net.MalformedURLException - File cannot be represented as a URL.

createNewFile

public boolean createNewFile()
Creates the the file denoted by this virtual file object.

Specified by:
createNewFile in interface StorageFile
Returns:
true if the file was successfully created, false otherwise

renameTo

public boolean renameTo(StorageFile newName)
Renames the file denoted by this handle.

Specified by:
renameTo in interface StorageFile
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 interface StorageFile
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 interface StorageFile
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.

Specified by:
length in interface StorageFile
Returns:
The length of the existing file, or 0 if the path denotes a directory or a non-existing file.

getParentDir

public StorageFile getParentDir()
Description copied from interface: StorageFile
Get the name of the parent directory if this name includes a parent.

Specified by:
getParentDir in interface StorageFile
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 interface StorageFile
Returns:
true if the named file or directory was made read-only, or it already was read-only; false if not.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.FileNotFoundException
Obtains an output stream for the file denoted.

If the file already exists, it will be truncated.

Specified by:
getOutputStream in interface StorageFile
Returns:
An OutputStream-instance.
Throws:
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 file

getOutputStream

public java.io.OutputStream getOutputStream(boolean append)
                                     throws java.io.FileNotFoundException
Obtains an output stream for the file denoted.

Specified by:
getOutputStream in interface StorageFile
Parameters:
append - tells if the file should be appended or truncated
Returns:
An OutputStream-instance.
Throws:
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 file

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.FileNotFoundException
Returns an input stream for the file denoted.

Specified by:
getInputStream in interface StorageFile
Returns:
An InputStream instance.
Throws:
java.io.FileNotFoundException - if the file doesn't exists or it is a directory

getExclusiveFileLock

public int 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 interface StorageFile
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.

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 interface StorageFile
See Also:
StorageFile.getExclusiveFileLock()

getRandomAccessFile

public StorageRandomAccessFile getRandomAccessFile(java.lang.String mode)
                                            throws java.io.FileNotFoundException
Creates a random access file that can be used to read and write from/into the file.

Specified by:
getRandomAccessFile in interface StorageFile
Parameters:
mode - file mode, one of "r", "rw", "rws" or "rwd" (lower-case letters are required)
Returns:
A StorageRandomAccessFile-instance.
Throws:
java.lang.IllegalArgumentException - if the specificed mode is invalid
java.io.FileNotFoundException - if the file denoted is a directory,
See Also:
java.io.RandomAccessFile

toString

public java.lang.String toString()
Returns a textual representation of this file.

Overrides:
toString in class java.lang.Object
Returns:
Textual representation.

getEntry

private DataStoreEntry 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.

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.