KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > io > StorageRandomAccessFile


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 JavaDoc;
25 import java.io.DataOutput JavaDoc;
26 import java.io.FileNotFoundException JavaDoc;
27 import java.io.EOFException JavaDoc;
28 import java.io.IOException JavaDoc;
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 JavaDoc, DataOutput JavaDoc
46 {
47
48     /**
49      * Closes this file.
50      *
51      * @exception IOException - if an I/O error occurs.
52      */

53     public void close() throws IOException JavaDoc;
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 JavaDoc;
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 JavaDoc;
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 JavaDoc;
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 JavaDoc;
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 JavaDoc;
110 }
111
Popular Tags