1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.io.DirRandomAccessFile4 |
4 | |
5 | Copyright 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.io; |
22 | |
23 | import java.io.File; |
24 | import java.io.FileNotFoundException; |
25 | import java.io.IOException; |
26 | import java.io.SyncFailedException; |
27 | import java.nio.channels.ClosedChannelException; |
28 | |
29 | /** |
30 | * This class provides a disk based implementation of the StIRandomAccess File interface. It is used by the |
31 | * database engine to access persistent data and transaction logs under the directory (default) subsubprotocol. |
32 | * |
33 | * This class extends DirRandomAccessFile to use the java.nio.channels.FileChannel.force() method to |
34 | * implement sync(). Java.nio.channels.FileChannel was introduced in Java 1.4; it was not available in Java 1.3. |
35 | */ |
36 | class DirRandomAccessFile4 extends DirRandomAccessFile |
37 | { |
38 | |
39 | |
40 | /** |
41 | * Construct a StorageRandomAccessFileImpl. |
42 | * |
43 | * @param name The file name. |
44 | * @param mode The file open mode: "r", "rw", "rws", or "rwd". The "rws" and "rwd" modes specify that the file is to |
45 | * be synchronized, consistent with the java.io.RandomAccessFile class. However the |
46 | * StorageRandomAccessFile.sync() method will be called even if the file was opened |
47 | * in "rws" or "rwd" mode. If the "rws" or "rwd" modes are supported then the implementation |
48 | * of StorageRandomAccessFile.sync need not do anything. |
49 | * |
50 | * @exception IllegalArgumentException if the mode argument is not equal to one of "r", "rw". |
51 | * @exception FileNotFoundException if the file exists but is a directory rather than a regular |
52 | * file, or cannot be opened or created for any other reason . |
53 | */ |
54 | DirRandomAccessFile4( File name, String mode) throws FileNotFoundException |
55 | { |
56 | super( name, mode); |
57 | } |
58 | |
59 | /** |
60 | * Force any changes out to the persistent store. |
61 | * |
62 | * @param metaData If true then this method is required to force changes to both the file's |
63 | * content and metadata to be written to storage; otherwise, it need only force content changes |
64 | * to be written. |
65 | * |
66 | * @exception IOException If an IO error occurs. |
67 | */ |
68 | public void sync( boolean metaData) throws IOException |
69 | { |
70 | try |
71 | { |
72 | getChannel().force( metaData); |
73 | } |
74 | catch( ClosedChannelException cce) { throw cce;} |
75 | catch( IOException ioe) |
76 | { |
77 | SyncFailedException sne = new SyncFailedException( ioe.getMessage()); |
78 | sne.initCause( ioe); |
79 | throw sne; |
80 | } |
81 | } // end of sync |
82 | } |