org.apache.derby.impl.io
Class InputStreamFile

java.lang.Object
  extended by org.apache.derby.impl.io.InputStreamFile
All Implemented Interfaces:
StorageFile
Direct Known Subclasses:
CPFile, JarDBFile, URLFile

abstract class InputStreamFile
extends java.lang.Object
implements StorageFile

This class provides the base for read-only stream implementations of the StorageFile interface. It is used with the classpath, jar, http, and https subsubprotocols


Field Summary
(package private)  int nameStart
           
(package private)  java.lang.String path
           
(package private)  BaseStorageFactory storageFactory
           
 
Fields inherited from interface org.apache.derby.io.StorageFile
EXCLUSIVE_FILE_LOCK, EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE, NO_FILE_LOCK_SUPPORT
 
Constructor Summary
InputStreamFile(BaseStorageFactory storageFactory, java.lang.String path)
           
InputStreamFile(BaseStorageFactory storageFactory, java.lang.String child, int pathLen)
           
InputStreamFile(BaseStorageFactory storageFactory, java.lang.String parent, java.lang.String name)
           
InputStreamFile(InputStreamFile dir, java.lang.String name)
           
 
Method Summary
 boolean canWrite()
          Determine whether the named file is writable.
 boolean createNewFile()
          If the named file does not already exist then create it as an empty normal file.
 boolean delete()
          Deletes the named file or empty directory.
 boolean deleteAll()
          Deletes the named file and, if it is a directory, all the files and directories it contains.
 boolean equals(java.lang.Object other)
           
abstract  boolean exists()
          Tests whether the named file exists.
 java.lang.String getCanonicalPath()
          Converts this StorageFile into a canonical pathname string.
 int getExclusiveFileLock()
          Get an exclusive lock with this name.
abstract  java.io.InputStream getInputStream()
          Creates an input stream from a file name.
 java.lang.String getName()
           
 java.io.OutputStream getOutputStream()
          Creates an output stream from a file name.
 java.io.OutputStream getOutputStream(boolean append)
          Creates an output stream from a file name.
 StorageFile getParentDir()
          Get the name of the parent directory if this name includes a parent.
(package private) abstract  StorageFile getParentDir(int pathLen)
          Get the parent of this file.
 java.lang.String getPath()
          Converts this StorageFile into a pathname string.
 StorageRandomAccessFile getRandomAccessFile(java.lang.String mode)
          Get a random access file.
 java.net.URL getURL()
          Get a URL representing this file.
 int hashCode()
           
 boolean isDirectory()
          Tests whether the named file is a directory, or not.
 long length()
          Returns the length of the named file if it is not a directory.
 java.lang.String[] list()
          Get the names of all files and sub-directories in the directory named by this path name.
 boolean mkdir()
          Creates the named directory.
 boolean mkdirs()
          Creates the named directory, and all nonexistent parent directories.
 void releaseExclusiveFileLock()
          Release the resource associated with an earlier acquired exclusive lock
 boolean renameTo(StorageFile newName)
          Rename the file denoted by this name.
 boolean setReadOnly()
          Make the named file or directory read-only.
 java.lang.String toString()
          Get the file name for diagnostic purposes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

path

final java.lang.String path

nameStart

final int nameStart

storageFactory

final BaseStorageFactory storageFactory
Constructor Detail

InputStreamFile

InputStreamFile(BaseStorageFactory storageFactory,
                java.lang.String path)

InputStreamFile

InputStreamFile(BaseStorageFactory storageFactory,
                java.lang.String parent,
                java.lang.String name)

InputStreamFile

InputStreamFile(InputStreamFile dir,
                java.lang.String name)

InputStreamFile

InputStreamFile(BaseStorageFactory storageFactory,
                java.lang.String child,
                int pathLen)
Method Detail

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

list

public java.lang.String[] list()
Get the names of all files and sub-directories in the directory named by this path name.

Specified by:
list in interface StorageFile
Returns:
An array of the names of the files and directories in this directory denoted by this abstract pathname. The returned array will have length 0 if this directory is empty. Returns null if this StorageFile is not a directory, or if an I/O error occurs.

canWrite

public boolean canWrite()
Determine whether the named file is writable.

Specified by:
canWrite in interface StorageFile
Returns:
true if the file exists and is writable, false if not.

exists

public abstract boolean exists()
Tests whether the named file exists.

Specified by:
exists in interface StorageFile
Returns:
true if the named file exists, false if not.

isDirectory

public boolean isDirectory()
Tests whether the named file is a directory, or not. This is only called in writable storage factories.

Specified by:
isDirectory in interface StorageFile
Returns:
true if named file exists and is a directory, false if not. The return value is undefined if the storage is read-only.

delete

public boolean delete()
Deletes the named file or empty directory. This method does not delete non-empty directories.

Specified by:
delete in interface StorageFile
Returns:
true if the named file or directory is successfully deleted, false if not

deleteAll

public boolean deleteAll()
Deletes the named file and, if it is a directory, all the files and directories it contains.

Specified by:
deleteAll in interface StorageFile
Returns:
true if the named file or directory is successfully deleted, false if not

getPath

public java.lang.String getPath()
Converts this StorageFile into a pathname string. The character returned by StorageFactory.getSeparator() is used to separate the directory and file names in the sequence.

The returned path may include the database directory. Therefore it cannot be directly used to make an StorageFile equivalent to this one.

Specified by:
getPath in interface StorageFile
Returns:
The pathname as a string.
See Also:
StorageFactory.getSeparator()

getCanonicalPath

public java.lang.String getCanonicalPath()
                                  throws java.io.IOException
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.
Throws:
java.io.IOException - if an I/O error occurred while finding the canonical name

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.

createNewFile

public boolean createNewFile()
                      throws java.io.IOException
If the named file does not already exist then create it as an empty normal file. The implementation must synchronize with other threads accessing the same file (in the same or a different process). If two threads both attempt to create a file with the same name at the same time then at most one should succeed.

Specified by:
createNewFile in interface StorageFile
Returns:
true if this thread's invocation of createNewFile successfully created the named file; false if not, i.e. false if the named file already exists or if another concurrent thread created it.
Throws:
java.io.IOException - - If the directory does not exist or some other I/O error occurred

renameTo

public boolean renameTo(StorageFile newName)
Rename the file denoted by this name. Note that StorageFile objects are immutable. This method renames the underlying file, it does not change this StorageFile object. The StorageFile object denotes the same name as before, however the exists() method will return false after the renameTo method executes successfully.

It is not specified whether this method will succeed if a file already exists under the new name.

Specified by:
renameTo in interface StorageFile
Parameters:
newName - the new name.
Returns:
true if the rename succeeded, false if not.

mkdir

public boolean mkdir()
Creates the named directory.

Specified by:
mkdir in interface StorageFile
Returns:
true if the directory was created; false if not.

mkdirs

public boolean mkdirs()
Creates the named directory, and all nonexistent parent directories.

Specified by:
mkdirs in interface StorageFile
Returns:
true if the directory was created, false if not

length

public long length()
Returns the length of the named file if it is not a directory. The return value is not specified if the file is a directory.

Specified by:
length in interface StorageFile
Returns:
The length, in bytes, of the named file if it exists and is not a directory, 0 if the file does not exist, or any value if the named file is a directory.

getParentDir

public StorageFile getParentDir()
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.

getParentDir

abstract StorageFile getParentDir(int pathLen)
Get the parent of this file.

Parameters:
pathLen - the length of the parent's path name.

setReadOnly

public boolean setReadOnly()
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
Creates an output stream from a file name. If a normal file already exists with this name it will first be truncated to zero length.

Specified by:
getOutputStream in interface StorageFile
Returns:
an output stream suitable for writing to the file.
Throws:
java.io.FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.

getOutputStream

public java.io.OutputStream getOutputStream(boolean append)
                                     throws java.io.FileNotFoundException
Creates an output stream from a file name. If a normal file already exists with this name it will first be truncated to zero length.

Specified by:
getOutputStream in interface StorageFile
Parameters:
append - If true then data will be appended to the end of the file, if it already exists. If false and a normal file already exists with this name the file will first be truncated to zero length.
Returns:
an output stream suitable for writing to the file.
Throws:
java.io.FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.

getInputStream

public abstract java.io.InputStream getInputStream()
                                            throws java.io.FileNotFoundException
Creates an input stream from a file name.

Specified by:
getInputStream in interface StorageFile
Returns:
an input stream suitable for reading from the file.
Throws:
java.io.FileNotFoundException - if the file is not found.

getExclusiveFileLock

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

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()
Release the resource associated with an earlier acquired exclusive lock

Specified by:
releaseExclusiveFileLock in interface StorageFile
See Also:
getExclusiveFileLock()

getRandomAccessFile

public StorageRandomAccessFile getRandomAccessFile(java.lang.String mode)
                                            throws java.io.FileNotFoundException
Get a random access file.

Specified by:
getRandomAccessFile in interface StorageFile
Parameters:
mode - "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specify that the data is to be written to persistent store, consistent with the java.io.RandomAccessFile class ("synchronized" with the persistent storage, in the file system meaning of the word "synchronized"). However the implementation is not required to implement the "rws" or "rwd" modes. The implementation may treat "rws" and "rwd" as "rw". It is up to the user of this interface to call the StorageRandomAccessFile.sync method. However, if the "rws" or "rwd" modes are supported and the RandomAccessFile was opened in "rws" or "rwd" mode then the implementation of StorageRandomAccessFile.sync need not do anything.
Returns:
an object that can be used for random access to the file.
Throws:
java.lang.IllegalArgumentException - if the mode argument is not equal to one of "r", "rw", "rws", or "rwd".
java.io.FileNotFoundException - if the file exists but is a directory rather than a regular file, or cannot be opened or created for any other reason .
See Also:
java.io.RandomAccessFile

toString

public java.lang.String toString()
Get the file name for diagnostic purposes. Usually the same as getPath().

Overrides:
toString in class java.lang.Object
Returns:
the file name

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

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.