KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > io > DirRandomAccessFile4


1 /*
2
3    Derby - Class org.apache.derby.impl.io.DirRandomAccessFile4
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.impl.io;
23
24 import java.io.File JavaDoc;
25 import java.io.FileNotFoundException JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.SyncFailedException JavaDoc;
28 import java.nio.channels.ClosedChannelException JavaDoc;
29
30 /**
31  * This class provides a disk based implementation of the StIRandomAccess File interface. It is used by the
32  * database engine to access persistent data and transaction logs under the directory (default) subsubprotocol.
33  *
34  * This class extends DirRandomAccessFile to use the java.nio.channels.FileChannel.force() method to
35  * implement sync(). Java.nio.channels.FileChannel was introduced in Java 1.4; it was not available in Java 1.3.
36  */

37 class DirRandomAccessFile4 extends DirRandomAccessFile
38 {
39
40
41     /**
42      * Construct a StorageRandomAccessFileImpl.
43      *
44      * @param name The file name.
45      * @param mode The file open mode: "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specify that the file is to
46      * be synchronized, consistent with the java.io.RandomAccessFile class. However the
47      * StorageRandomAccessFile.sync() method will be called even if the file was opened
48      * in "rws" or "rwd" mode. If the "rws" or "rwd" modes are supported then the implementation
49      * of StorageRandomAccessFile.sync need not do anything.
50      *
51      * @exception IllegalArgumentException if the mode argument is not equal to one of "r", "rw".
52      * @exception FileNotFoundException if the file exists but is a directory rather than a regular
53      * file, or cannot be opened or created for any other reason .
54      */

55     DirRandomAccessFile4( File JavaDoc name, String JavaDoc mode) throws FileNotFoundException JavaDoc
56     {
57         super( name, mode);
58     }
59
60     /**
61      * Force any changes out to the persistent store.
62      *
63      * @param metaData If true then this method is required to force changes to both the file's
64      * content and metadata to be written to storage; otherwise, it need only force content changes
65      * to be written.
66      *
67      * @exception IOException If an IO error occurs.
68      */

69     public void sync( boolean metaData) throws IOException JavaDoc
70     {
71         try
72         {
73             getChannel().force( metaData);
74         }
75         catch( ClosedChannelException JavaDoc cce) { throw cce;}
76         catch( IOException JavaDoc ioe)
77         {
78             SyncFailedException JavaDoc sne = new SyncFailedException JavaDoc( ioe.getMessage());
79             sne.initCause( ioe);
80             throw sne;
81         }
82     } // end of sync
83
}
84
Popular Tags