OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / libjava / java / io / RandomAccessFile.java
1 // RandomAccessFile.java
2
3 /* Copyright (C) 1998, 1999  Cygnus Solutions
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 package java.io;
12
13 /**
14  * @author Tom Tromey <tromey@cygnus.com>
15  * @date September 25, 1998 
16  */
17
18 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
19  * "The Java Language Specification", ISBN 0-201-63451-1
20  * Status:  not finished
21  */
22
23 public class RandomAccessFile implements DataOutput, DataInput
24 {
25   public void close () throws IOException
26   {
27     fd.close();
28   }
29
30   public final FileDescriptor getFD () throws IOException
31   {
32     if (! fd.valid())
33       throw new IOException ();
34     return fd;
35   }
36
37   public long getFilePointer () throws IOException
38   {
39     return fd.getFilePointer();
40   }
41
42   public long length () throws IOException
43   {
44     return fd.length();
45   }
46
47   public RandomAccessFile (String fileName, String mode) throws IOException
48   {
49     int fdmode;
50     if (mode.compareTo ("r") == 0)
51       fdmode = FileDescriptor.READ;
52     else if (mode.compareTo ("rw") == 0)
53       fdmode = FileDescriptor.READ | FileDescriptor.WRITE;
54     else
55       throw new IllegalArgumentException ("invalid mode: " + mode);
56
57     SecurityManager s = System.getSecurityManager();
58     if (s != null)
59       {
60         s.checkRead(fileName);
61         if ((fdmode & FileDescriptor.WRITE) != 0)
62           s.checkWrite(fileName);
63       }
64
65     fd = new FileDescriptor (fileName, fdmode);
66     // FIXME: read-only mode.
67     out = new DataOutputStream (new FileOutputStream (fd));
68     in = new DataInputStream (new FileInputStream (fd));
69   }
70
71   public RandomAccessFile (File file, String mode) throws IOException
72   {
73     this (file.getPath(), mode);
74   }
75
76   public int read () throws IOException
77   {
78     return in.read();
79   }
80
81   public int read (byte[] buffer) throws IOException
82   {
83     return in.read(buffer);
84   }
85
86   public int read (byte[] buffer, int offset, int count) throws IOException
87   {
88     return in.read(buffer, offset, count);
89   }
90
91   public final boolean readBoolean () throws IOException
92   {
93     return in.readBoolean();
94   }
95
96   public final byte readByte () throws IOException
97   {
98     return in.readByte();
99   }
100
101   public final char readChar () throws IOException
102   {
103     return in.readChar();
104   }
105
106   public final double readDouble () throws IOException
107   {
108     return in.readDouble();
109   }
110
111   public final float readFloat () throws IOException
112   {
113     return in.readFloat();
114   }
115
116   public final void readFully (byte[] buffer) throws IOException
117   {
118     // FIXME.
119   }
120
121   public final void readFully (byte[] buffer, int offset, int count)
122     throws IOException
123   {
124     // FIXME.
125   }
126
127   public final int readInt () throws IOException
128   {
129     return in.readInt();
130   }
131
132   public final String readLine () throws IOException
133   {
134     // FIXME?
135     return in.readLine();
136   }
137
138   public final long readLong () throws IOException
139   {
140     return in.readLong();
141   }
142
143   public final short readShort () throws IOException
144   {
145     return in.readShort();
146   }
147
148   public final int readUnsignedByte () throws IOException
149   {
150     return in.readUnsignedByte();
151   }
152
153   public final int readUnsignedShort () throws IOException
154   {
155     return in.readUnsignedShort();
156   }
157
158   public final String readUTF () throws IOException
159   {
160     return in.readUTF();
161   }
162
163   public void seek (long pos) throws IOException
164   {
165     fd.seek(pos, FileDescriptor.SET);
166   }
167
168   public int skipBytes (int count) throws IOException
169   {
170     return fd.seek(count, FileDescriptor.CUR);
171   }
172
173   public void write (int oneByte) throws IOException
174   {
175     out.write(oneByte);
176   }
177
178   public void write (byte[] buffer) throws IOException
179   {
180     out.write(buffer);
181   }
182
183   public void write (byte[] buffer, int offset, int count) throws IOException
184   {
185     out.write(buffer, offset, count);
186   }
187
188   public final void writeBoolean (boolean val) throws IOException
189   {
190     out.writeBoolean(val);
191   }
192
193   public final void writeByte (int v) throws IOException
194   {
195     out.writeByte(v);
196   }
197
198   public final void writeShort (int v) throws IOException
199   {
200     out.writeShort(v);
201   }
202
203   public final void writeChar (int v) throws IOException
204   {
205     out.writeChar(v);
206   }
207
208   public final void writeInt (int v) throws IOException
209   {
210     out.writeInt(v);
211   }
212
213   public final void writeLong (long v) throws IOException
214   {
215     out.writeLong(v);
216   }
217
218   public final void writeFloat (float v) throws IOException
219   {
220     out.writeFloat(v);
221   }
222
223   public final void writeDouble (double v) throws IOException
224   {
225     out.writeDouble(v);
226   }
227
228   public final void writeBytes (String s) throws IOException
229   {
230     out.writeBytes(s);
231   }
232
233   public final void writeChars (String s) throws IOException
234   {
235     out.writeChars(s);
236   }
237   
238   public final void writeUTF (String s) throws IOException
239   {
240     out.writeUTF(s);
241   }
242
243
244   // The underlying file.
245   private FileDescriptor fd;
246   // The corresponding input and output streams.
247   private DataOutputStream out;
248   private DataInputStream in;
249 }