Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / io / StorageFile.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/io/StorageFile.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/io/StorageFile.java
new file mode 100644 (file)
index 0000000..3c4d30c
--- /dev/null
@@ -0,0 +1,291 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.io.StorageFile\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.io;\r
+\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.net.URL;\r
+import java.net.MalformedURLException;\r
+\r
+/**\r
+ * This interface abstracts file naming. Any method in this interface\r
+ * that also appears in the java.io.File class should behave as the java.io.File method does.\r
+ *<p>\r
+ * When used by the database engine all files will be under either the database\r
+ * directory, specified by the databaseName argument of the {@link\r
+ * StorageFactory#init StorageFactory.init} method, or under the temporary file\r
+ * directory returned by the {@link StorageFactory#getTempDir\r
+ * StorageFactory.getTempDir} method. All relative path names are relative to\r
+ * the database directory.\r
+ *<p>\r
+ * The database engine will call this interface's methods from its own privilege blocks.\r
+ *<p>\r
+ * Different threads may operate on the same underlying file at the same time, either through the\r
+ * same or different StorageFile objects. The StiFile implementation must be capable of handling this.\r
+ *<p>\r
+ * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html">java.io.File</a>\r
+ */\r
+public interface StorageFile\r
+{\r
+\r
+       //constant values related to exclusive lock mechanism\r
+       public static final int NO_FILE_LOCK_SUPPORT              = 0;\r
+       public static final int EXCLUSIVE_FILE_LOCK               = 1;\r
+       public static final int EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE = 2;\r
+\r
+    /**\r
+     * Get the names of all files and sub-directories in the directory named by this path name.\r
+     *\r
+     * This method is only used in a writable database.\r
+     *\r
+     * @return An array of the names of the files and directories in this\r
+     *         directory denoted by this abstract pathname. The returned array will have length 0\r
+     *         if this directory is empty. Returns null if this StorageFile is not  a directory, or\r
+     *         if an I/O error occurs. The return value is undefined if the database is read-only.\r
+     */\r
+    public String[] list();\r
+\r
+    /**\r
+     * Determine whether the named file is writable.\r
+     *\r
+     * @return <b>true</b> if the file exists and is writable, <b>false</b> if not.\r
+     */\r
+    public boolean canWrite();\r
+\r
+    /**\r
+     * Tests whether the named file exists.\r
+     *\r
+     * @return <b>true</b> if the named file exists, <b>false</b> if not.\r
+     */\r
+    public boolean exists();\r
+\r
+    /**\r
+     * Tests whether the named file is a directory, or not. This is only called in writable storage factories.\r
+     *\r
+     * @return <b>true</b> if named file exists and is a directory, <b>false</b> if not.\r
+     *          The return value is undefined if the storage is read-only.\r
+     */\r
+    public boolean isDirectory();\r
+\r
+    /**\r
+     * Deletes the named file or empty directory. This method does not delete non-empty directories.\r
+     *\r
+     * @return <b>true</b> if the named file or directory is successfully deleted, <b>false</b> if not\r
+     */\r
+    public boolean delete();\r
+\r
+    /**\r
+     * Deletes the named file and, if it is a directory, all the files and directories it contains.\r
+     *\r
+     * @return <b>true</b> if the named file or directory is successfully deleted, <b>false</b> if not\r
+     */\r
+    public boolean deleteAll();\r
+\r
+    /**\r
+     * Converts this StorageFile into a pathname string. The character returned by StorageFactory.getSeparator()\r
+     * is used to separate the directory and file names in the sequence.\r
+     *\r
+     *<p>\r
+     *<b>The returned path may include the database directory. Therefore it cannot be directly used to make an StorageFile\r
+     * equivalent to this one.</b>\r
+     *\r
+     * @return The pathname as a string.\r
+     *\r
+     * @see StorageFactory#getSeparator\r
+     */\r
+    public String getPath();\r
+\r
+    /**\r
+     * Converts this StorageFile into a canonical pathname string. The form of the canonical path is system dependent.\r
+     *\r
+     * @return The pathname as a string.\r
+     *\r
+     * @exception IOException if an I/O error occurred while finding the canonical name\r
+     */\r
+    public String getCanonicalPath() throws IOException;\r
+\r
+    /**\r
+     * @return The last segment in the path name, "" if the path name sequence is empty.\r
+     */\r
+    public String getName();\r
+    \r
+    /**\r
+     * Get a URL representing this file. A valid URL does not indicate the file exists,\r
+     * it may just be a URL that will fail on opening. Some implementations\r
+     * return null if the file does not exist. \r
+     * @throws MalformedURLException File cannot be represented as a URL.\r
+     */\r
+    public URL getURL() throws MalformedURLException;\r
+    \r
+    /**\r
+     * If the named file does not already exist then create it as an empty normal file.\r
+     *\r
+     * The implementation\r
+     * must synchronize with other threads accessing the same file (in the same or a different process).\r
+     * If two threads both attempt to create a file with the same name\r
+     * at the same time then at most one should succeed.\r
+     *\r
+     * @return <b>true</b> if this thread's invocation of createNewFile successfully created the named file;\r
+     *         <b>false</b> if not, i.e. <b>false</b> if the named file already exists or if another concurrent thread created it.\r
+     *\r
+     * @exception IOException - If the directory does not exist or some other I/O error occurred\r
+     */\r
+    public boolean createNewFile() throws IOException;\r
+\r
+    /**\r
+     * Rename the file denoted by this name. Note that StorageFile objects are immutable. This method\r
+     * renames the underlying file, it does not change this StorageFile object. The StorageFile object denotes the\r
+     * same name as before, however the exists() method will return false after the renameTo method\r
+     * executes successfully.\r
+     *\r
+     *<p>It is not specified whether this method will succeed if a file already exists under the new name.\r
+     *\r
+     * @param newName the new name.\r
+     *\r
+     * @return <b>true</b> if the rename succeeded, <b>false</b> if not.\r
+     */\r
+    public boolean renameTo( StorageFile newName);\r
+    \r
+    /**\r
+     * Creates the named directory.\r
+     *\r
+     * @return <b>true</b> if the directory was created; <b>false</b> if not.\r
+     */\r
+    public boolean mkdir();\r
+\r
+    /**\r
+     * Creates the named directory, and all nonexistent parent directories.\r
+     *\r
+     * @return <b>true</b> if the directory was created, <b>false</b> if not\r
+     */\r
+    public boolean mkdirs();\r
+\r
+    /**\r
+     * Returns the length of the named file if it is not a directory. The return value is not specified\r
+     * if the file is a directory.\r
+     *\r
+     * @return The length, in bytes, of the named file if it exists and is not a directory,\r
+     *         0 if the file does not exist, or any value if the named file is a directory.\r
+     */\r
+    public long length();\r
+\r
+    /**\r
+     * Get the name of the parent directory if this name includes a parent.\r
+     *\r
+     * @return An StorageFile denoting the parent directory of this StorageFile, if it has a parent, null if\r
+     *         it does not have a parent.\r
+     */\r
+    public StorageFile getParentDir();\r
+\r
+    /**\r
+     * Make the named file or directory read-only. This interface does not specify whether this\r
+     * also makes the file undeletable.\r
+     *\r
+     * @return <b>true</b> if the named file or directory was made read-only, or it already was read-only;\r
+     *         <b>false</b> if not.\r
+     */\r
+    public boolean setReadOnly();\r
+\r
+    /**\r
+     * Creates an output stream from a file name. If a normal file already exists with this name it\r
+     * will first be truncated to zero length.\r
+     *\r
+     * @return an output stream suitable for writing to the file.\r
+     *\r
+     * @exception FileNotFoundException if the file exists but is a directory\r
+     *            rather than a regular file, does not exist but cannot be created, or\r
+     *            cannot be opened for any other reason.\r
+     */\r
+    public OutputStream getOutputStream( ) throws FileNotFoundException;\r
+\r
+    /**\r
+     * Creates an output stream from a file name.\r
+     *\r
+     * @param append If true then data will be appended to the end of the file, if it already exists.\r
+     *               If false and a normal file already exists with this name the file will first be truncated\r
+     *               to zero length.\r
+     *\r
+     * @return an output stream suitable for writing to the file.\r
+     *\r
+     * @exception FileNotFoundException if the file exists but is a directory\r
+     *            rather than a regular file, does not exist but cannot be created, or\r
+     *            cannot be opened for any other reason.\r
+     */\r
+    public OutputStream getOutputStream( boolean append) throws FileNotFoundException;\r
+    \r
+    /**\r
+     * Creates an input stream from a file name.\r
+     *\r
+     * @return an input stream suitable for reading from the file.\r
+     *\r
+     * @exception FileNotFoundException if the file is not found.\r
+     */\r
+    public InputStream getInputStream( ) throws FileNotFoundException;\r
+\r
+    /**\r
+     * Get an exclusive lock with this name. This is used to ensure that two or more JVMs do not open the same database\r
+     * at the same time.\r
+     *\r
+     * @return EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE if the lock cannot be acquired because it is already held.<br>\r
+     *    EXCLUSIVE_FILE_LOCK if the lock was successfully acquired.<br>\r
+     *    NO_FILE_LOCK_SUPPORT if the system does not support exclusive locks.<br>\r
+     */\r
+    public int getExclusiveFileLock();\r
+\r
+       /**\r
+     * Release the resource associated with an earlier acquired exclusive lock\r
+     *\r
+     * @see #getExclusiveFileLock\r
+     */\r
+       public void releaseExclusiveFileLock();\r
+\r
+    /**\r
+     * Get a random access file.\r
+     *\r
+     * This method is not called if the StorageFactory is read only. It is unspecified if the StorageFactory\r
+     * that created it is not a WritableStorageFactory.\r
+     *\r
+     * @param mode "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specify\r
+     *             that the data is to be written to persistent store, consistent with the\r
+     *             java.io.RandomAccessFile class ("synchronized" with the persistent\r
+     *             storage, in the file system meaning of the word "synchronized").  However\r
+     *             the implementation is not required to implement the "rws" or "rwd"\r
+     *             modes. If the "rws" andr "rwd" modes are supported then the supportsRws() method\r
+     *             of the StorageFactory returns true. If supportsRws() returns false then the\r
+     *             implementation may treat "rws" and "rwd" as "rw". It is up to\r
+     *             the user of this interface to call the StorageRandomAccessFile.sync\r
+     *             method if necessary. However, if the "rws" or "rwd" modes are supported and the\r
+     *             RandomAccessFile was opened in "rws" or "rwd" mode then the\r
+     *             implementation of StorageRandomAccessFile.sync need not do anything.\r
+     *\r
+     * @return an object that can be used for random access to the file.\r
+     *\r
+     * @exception IllegalArgumentException if the mode argument is not equal to one of "r", "rw", "rws", or "rwd".\r
+     * @exception FileNotFoundException if the file exists but is a directory rather than a regular\r
+     *              file, or cannot be opened or created for any other reason .\r
+     *\r
+     * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html">java.io.RandomAccessFile</a>\r
+     */\r
+    public StorageRandomAccessFile getRandomAccessFile( String mode) throws FileNotFoundException;\r
+}\r