diff options
author | Tom Tromey <tromey@redhat.com> | 2003-04-21 19:44:08 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2003-04-21 19:44:08 +0000 |
commit | 5eab453e0fec2954ba1bc3d9ea437805511bc203 (patch) | |
tree | 5ca6997c13754e8d876fbcaeccfa7243740e5cef /java/io/RandomAccessFile.java | |
parent | f9fdf51d902e68d3e6348f32c2c8daa9229a0e32 (diff) | |
download | classpath-5eab453e0fec2954ba1bc3d9ea437805511bc203.tar.gz |
* include/java_io_FileDescriptor.h: Rebuilt.
* java/io/FileInputStream.java (FileInputStream): Updated for
changes to FileDescriptor.
(FileInputStream(FileDescriptor)): Don't throw SecurityException
if fd is invalid.
* java/io/FileOutputStream.java (FileOutputStream): Updated for
changes to FileDescriptor. Don't throw SecurityException if fd
is invalid.
* java/io/RandomAccessFile.java (RandomAccessFile): Updated for
changes to FileDescriptor.
(readOnly): Removed; updated all users.
* java/io/FileDescriptor.java (SET, CUR, END): Now constants.
(READ, WRITE, APPEND, EXCL, SYNC): New constants.
(in, out, err): Require nativeInit to initialize.
(FileDescriptor(String,int)): New constructor.
(open): Changed argument type of `mode'. Allow empty paths.
Only throw runtime errors or FileNotFoundException.
(nativeValid): Don't throw IOException.
(valid): Simplified.
(nativeOpen): Throw FileNotFoundException. Changed type of
`mode' argument.
* native/jni/java-io/FileDescriptor.c
(Java_java_io_FileDescriptor_nativeValid): Updated comment.
(SET, CUR, END, READ, WRITE, APPEND, EXCL, SYNC): New defines.
(Java_java_io_FileDescriptor_nativeOpen): Changed type of mode
argument.
(true): Don't define; use JNI_TRUE.
(false): Don't define; use JNI_FALSE.
(INIT_FIELD): New define.
(Java_java_io_FileDescriptor_nativeInit): Rewrote.
* native/jni/java-io/java_io_FileDescriptor.c: Removed.
Diffstat (limited to 'java/io/RandomAccessFile.java')
-rw-r--r-- | java/io/RandomAccessFile.java | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/java/io/RandomAccessFile.java b/java/io/RandomAccessFile.java index 4ddd16748..14c771ae0 100644 --- a/java/io/RandomAccessFile.java +++ b/java/io/RandomAccessFile.java @@ -65,11 +65,6 @@ public class RandomAccessFile implements DataOutput, DataInput private FileChannel ch; /* cached associated file-channel */ - /** - * Whether or not this file is open in read only mode - */ - private boolean readOnly; - // Used for DataOutput methods writing values to the underlying file private byte[] buf = new byte[8]; @@ -101,15 +96,17 @@ public class RandomAccessFile implements DataOutput, DataInput /** * This method initializes a new instance of <code>RandomAccessFile</code> * to read from the specified file name with the specified access mode. - * The access mode is either "r" for read only access or "rw" for read - * write access. + * The access mode is either "r" for read only access, "rw" for read + * write access, "rws" for synchronized read/write access of both + * content and metadata, or "rwd" for read/write access + * where only content is required to be synchronous. * <p> * Note that a <code>SecurityManager</code> check is made prior to * opening the file to determine whether or not this file is allowed to * be read or written. * * @param fileName The name of the file to read and/or write - * @param mode "r" for read only or "rw" for read-write access to the file + * @param mode "r", "rw", "rws", or "rwd" * * @exception IllegalArgumentException If <code>mode</code> has an * illegal value @@ -120,33 +117,31 @@ public class RandomAccessFile implements DataOutput, DataInput public RandomAccessFile (String fileName, String mode) throws FileNotFoundException { - // Check the mode - if (!mode.equals("r") && !mode.equals("rw") && !mode.equals("rws") && - !mode.equals("rwd")) + int fdmode; + if (mode.equals("r")) + fdmode = FileDescriptor.READ; + else if (mode.equals("rw")) + fdmode = FileDescriptor.READ | FileDescriptor.WRITE; + else if (mode.equals("rws") || mode.equals("rwd")) + { + // FIXME: for now we treat rws and rwd and synonyms. + fdmode = (FileDescriptor.READ | FileDescriptor.WRITE + | FileDescriptor.SYNC); + } + else throw new IllegalArgumentException("Bad mode value: " + mode); - + // The obligatory SecurityManager stuff SecurityManager s = System.getSecurityManager(); if (s != null) { s.checkRead(fileName); - if (!mode.equals("r")) + if ((fdmode & FileDescriptor.WRITE) != 0) s.checkWrite(fileName); } - - if (mode.equals("r")) - readOnly = true; - - fd = new FileDescriptor(); - try - { - fd.open(fileName, mode); - } - catch(IOException e) - { - throw new FileNotFoundException(e.getMessage()); - } + + fd = new FileDescriptor(fileName, fdmode); } /** @@ -205,9 +200,6 @@ public class RandomAccessFile implements DataOutput, DataInput */ public void setLength(long newlen) throws IOException { - if (readOnly) - throw new IOException("File is open read only"); - fd.setLength(newlen); } @@ -824,9 +816,6 @@ public class RandomAccessFile implements DataOutput, DataInput */ public void write (int oneByte) throws IOException { - if (readOnly) - throw new IOException("File is open read only"); - fd.write (oneByte); } @@ -853,9 +842,6 @@ public class RandomAccessFile implements DataOutput, DataInput */ public void write (byte[] buffer, int offset, int len) throws IOException { - if (readOnly) - throw new IOException("File is open read only"); - fd.write (buffer, offset, len); } |