Save This Page
Home » db-derby-10.5.3.0 » org.apache.derby.io » [javadoc | source]
    1   /*
    2   
    3      Derby - Class org.apache.derby.io.StorageRandomAccessFile
    4   
    5      Licensed to the Apache Software Foundation (ASF) under one or more
    6      contributor license agreements.  See the NOTICE file distributed with
    7      this work for additional information regarding copyright ownership.
    8      The ASF licenses this file to You under the Apache License, Version 2.0
    9      (the "License"); you may not use this file except in compliance with
   10      the License.  You may obtain a copy of the License at
   11   
   12         http://www.apache.org/licenses/LICENSE-2.0
   13   
   14      Unless required by applicable law or agreed to in writing, software
   15      distributed under the License is distributed on an "AS IS" BASIS,
   16      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   17      See the License for the specific language governing permissions and
   18      limitations under the License.
   19   
   20    */
   21   
   22   package org.apache.derby.io;
   23   
   24   import java.io.DataInput;
   25   import java.io.DataOutput;
   26   import java.io.FileNotFoundException;
   27   import java.io.EOFException;
   28   import java.io.IOException;
   29   
   30   /**
   31    * This interface abstracts an object that implements reading and writing on a random access
   32    * file. It extends DataInput and DataOutput, so it implicitly contains all the methods of those
   33    * interfaces. Any method in this interface that also appears in the java.io.RandomAccessFile class
   34    * should behave as the java.io.RandomAccessFile method does.
   35    *<p>
   36    * Each StorageRandomAccessFile has an associated file pointer, a byte offset in the file. All reading and writing takes
   37    * place at the file pointer offset and advances it.
   38    *<p>
   39    * An implementation of StorageRandomAccessFile need not be thread safe. The database engine
   40    * single-threads access to each StorageRandomAccessFile instance. Two threads will not access the
   41    * same StorageRandomAccessFile instance at the same time.
   42    *<p>
   43    * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html">java.io.RandomAccessFile</a>
   44    */
   45   public interface StorageRandomAccessFile extends DataInput, DataOutput
   46   {
   47   
   48       /**
   49        * Closes this file.
   50        *
   51        * @exception IOException - if an I/O error occurs.
   52        */
   53       public void close() throws IOException;
   54   
   55       /**
   56        * Get the current offset in this file.
   57        *
   58        * @return the current file pointer. 
   59        *
   60        * @exception IOException - if an I/O error occurs.
   61        */
   62       public long getFilePointer() throws IOException;
   63   
   64       /**
   65        * Gets the length of this file.
   66        *
   67        * @return the number of bytes this file. 
   68        *
   69        * @exception IOException - if an I/O error occurs.
   70        */
   71       public long length() throws IOException;
   72   
   73       /**
   74        * Set the file pointer. It may be moved beyond the end of the file, but this does not change
   75        * the length of the file. The length of the file is not changed until data is actually written..
   76        *
   77        * @param newFilePointer the new file pointer, measured in bytes from the beginning of the file.
   78        *
   79        * @exception IOException - if newFilePointer is less than 0 or an I/O error occurs.
   80        */
   81       public void seek(long newFilePointer) throws IOException;
   82   
   83       /**
   84        * Sets the length of this file, either extending or truncating it.
   85        *<p>
   86        * If the file is extended then the contents of the extension are not defined.
   87        *<p>
   88        * If the file is truncated and the file pointer is greater than the new length then the file pointer
   89        * is set to the new length.
   90        *
   91        * @param newLength The new file length.
   92        *
   93        * @exception IOException If an I/O error occurs.
   94        */
   95       public void setLength(long newLength) throws IOException;
   96       
   97       /**
   98        * Force any changes out to the persistent store. If the database is to be transient, that is, if the database
   99        * does not survive a restart, then the sync method implementation need not do anything.
  100        *
  101        * @param metaData If true then this method must force both changes to the file's
  102        *          contents and metadata to be written to storage; if false, it need only force file content changes
  103        *          to be written. The implementation is allowed to ignore this parameter and always force out
  104        *          metadata changes.
  105        *
  106        * @exception SyncFailedException if a possibly recoverable error occurs.
  107        * @exception IOException If an IO error occurs.
  108        */
  109       public void sync( boolean metaData) throws IOException;
  110   
  111       /**
  112        * Reads up to <code>len</code> bytes of data from this file into an
  113        * array of bytes. This method blocks until at least one byte of input
  114        * is available.
  115        * <p>
  116        *
  117        * @param b     the buffer into which the data is read.
  118        * @param off   the start offset in array <code>b</code>
  119        *                   at which the data is written.
  120        * @param len   the maximum number of bytes read.
  121        * @return the total number of bytes read into the buffer, or
  122        *             <code>-1</code> if there is no more data because the end of
  123        *             the file has been reached.
  124        * @exception IOException If the first byte cannot be read for any reason
  125        * other than end of file, or if the random access file has been closed, or
  126        * if some other I/O error occurs.
  127        * @exception NullPointerException If <code>b</code> is <code>null</code>.
  128        * @exception IndexOutOfBoundsException If <code>off</code> is negative,
  129        * <code>len</code> is negative, or <code>len</code> is greater than
  130        * <code>b.length - off</code>
  131        */
  132       public int read(byte[] b, int off, int len) throws IOException;
  133   }

Save This Page
Home » db-derby-10.5.3.0 » org.apache.derby.io » [javadoc | source]