1 // RandomAccessFile.java
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date September 25, 1998
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
23 public class RandomAccessFile implements DataOutput, DataInput
25 public void close () throws IOException
30 public final FileDescriptor getFD () throws IOException
33 throw new IOException ();
37 public long getFilePointer () throws IOException
39 return fd.getFilePointer();
42 public long length () throws IOException
47 public RandomAccessFile (String fileName, String mode) throws IOException
50 if (mode.compareTo ("r") == 0)
51 fdmode = FileDescriptor.READ;
52 else if (mode.compareTo ("rw") == 0)
53 fdmode = FileDescriptor.READ | FileDescriptor.WRITE;
55 throw new IllegalArgumentException ("invalid mode: " + mode);
57 SecurityManager s = System.getSecurityManager();
60 s.checkRead(fileName);
61 if ((fdmode & FileDescriptor.WRITE) != 0)
62 s.checkWrite(fileName);
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));
71 public RandomAccessFile (File file, String mode) throws IOException
73 this (file.getPath(), mode);
76 public int read () throws IOException
81 public int read (byte[] buffer) throws IOException
83 return in.read(buffer);
86 public int read (byte[] buffer, int offset, int count) throws IOException
88 return in.read(buffer, offset, count);
91 public final boolean readBoolean () throws IOException
93 return in.readBoolean();
96 public final byte readByte () throws IOException
101 public final char readChar () throws IOException
103 return in.readChar();
106 public final double readDouble () throws IOException
108 return in.readDouble();
111 public final float readFloat () throws IOException
113 return in.readFloat();
116 public final void readFully (byte[] buffer) throws IOException
121 public final void readFully (byte[] buffer, int offset, int count)
127 public final int readInt () throws IOException
132 public final String readLine () throws IOException
135 return in.readLine();
138 public final long readLong () throws IOException
140 return in.readLong();
143 public final short readShort () throws IOException
145 return in.readShort();
148 public final int readUnsignedByte () throws IOException
150 return in.readUnsignedByte();
153 public final int readUnsignedShort () throws IOException
155 return in.readUnsignedShort();
158 public final String readUTF () throws IOException
163 public void seek (long pos) throws IOException
165 fd.seek(pos, FileDescriptor.SET);
168 public int skipBytes (int count) throws IOException
170 return fd.seek(count, FileDescriptor.CUR);
173 public void write (int oneByte) throws IOException
178 public void write (byte[] buffer) throws IOException
183 public void write (byte[] buffer, int offset, int count) throws IOException
185 out.write(buffer, offset, count);
188 public final void writeBoolean (boolean val) throws IOException
190 out.writeBoolean(val);
193 public final void writeByte (int v) throws IOException
198 public final void writeShort (int v) throws IOException
203 public final void writeChar (int v) throws IOException
208 public final void writeInt (int v) throws IOException
213 public final void writeLong (long v) throws IOException
218 public final void writeFloat (float v) throws IOException
223 public final void writeDouble (double v) throws IOException
228 public final void writeBytes (String s) throws IOException
233 public final void writeChars (String s) throws IOException
238 public final void writeUTF (String s) throws IOException
244 // The underlying file.
245 private FileDescriptor fd;
246 // The corresponding input and output streams.
247 private DataOutputStream out;
248 private DataInputStream in;