Commit e48d8b88 by Michael Koch Committed by Michael Koch

2003-05-13 Michael Koch <konqueror@gmx.de>

       * java/io/FileDescriptor.java
       (SYNC): New constant.
       (DSYNC): Likewise.
       (getLength): Renamed from lenght() to match classpath's
       FileDescriptor.java.
       * java/io/RandomAccessFile.java
       (RandomAccessFile): Removed unneeded mode check, implemented mode
       "rws" and "rwd", merged documentation from classpath.
       (setLength): Reformatted.
       (length): Use new getLength() of FileDescriptor.
       * java/io/natFileDescriptorEcos.cc
       (getLength): Renamed from length().
       * java/io/natFileDescriptorPosix.cc
       (open): Implemented support for SYNC and DSYNC.
       (seek): Use getLength() instead of length().
       (getLength): Renamed from length().
       * java/io/natFileDescriptorWin32.cc
       (getLength): Renamed from length().
       (seek): Use getLength() instead of length().
       (available): Likewise.
       * gnu/java/nio/natFileChannelImpl.cc
       (size): Use getLength() instead of length().

From-SVN: r66755
parent aa8f1f57
2003-05-13 Michael Koch <konqueror@gmx.de> 2003-05-13 Michael Koch <konqueror@gmx.de>
* java/io/FileDescriptor.java
(SYNC): New constant.
(DSYNC): Likewise.
(getLength): Renamed from lenght() to match classpath's
FileDescriptor.java.
* java/io/RandomAccessFile.java
(RandomAccessFile): Removed unneeded mode check, implemented mode
"rws" and "rwd", merged documentation from classpath.
(setLength): Reformatted.
(length): Use new getLength() of FileDescriptor.
* java/io/natFileDescriptorEcos.cc
(getLength): Renamed from length().
* java/io/natFileDescriptorPosix.cc
(open): Implemented support for SYNC and DSYNC.
(seek): Use getLength() instead of length().
(getLength): Renamed from length().
* java/io/natFileDescriptorWin32.cc
(getLength): Renamed from length().
(seek): Use getLength() instead of length().
(available): Likewise.
* gnu/java/nio/natFileChannelImpl.cc
(size): Use getLength() instead of length().
2003-05-13 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/ByteBufferImpl.java * gnu/java/nio/ByteBufferImpl.java
(ByteBufferImpl): All constructors revised. (ByteBufferImpl): All constructors revised.
(slice): Reimplemented. (slice): Reimplemented.
......
...@@ -34,7 +34,7 @@ details. */ ...@@ -34,7 +34,7 @@ details. */
jlong jlong
gnu::java::nio::FileChannelImpl::size () gnu::java::nio::FileChannelImpl::size ()
{ {
return fd->length (); return fd->getLength ();
} }
jlong jlong
......
...@@ -44,6 +44,8 @@ public final class FileDescriptor ...@@ -44,6 +44,8 @@ public final class FileDescriptor
static final int APPEND = 4; static final int APPEND = 4;
// EXCL is used only when making a temp file. // EXCL is used only when making a temp file.
static final int EXCL = 8; static final int EXCL = 8;
static final int SYNC = 16;
static final int DSYNC = 32;
// These are WHENCE values for seek. // These are WHENCE values for seek.
static final int SET = 0; static final int SET = 0;
...@@ -71,7 +73,7 @@ public final class FileDescriptor ...@@ -71,7 +73,7 @@ public final class FileDescriptor
// past the end is ok (and if a subsequent write occurs the file // past the end is ok (and if a subsequent write occurs the file
// will grow). // will grow).
native int seek (long pos, int whence, boolean eof_trunc) throws IOException; native int seek (long pos, int whence, boolean eof_trunc) throws IOException;
native long length () throws IOException; native long getLength () throws IOException;
native long getFilePointer () throws IOException; native long getFilePointer () throws IOException;
native int read () throws IOException; native int read () throws IOException;
native int read (byte[] bytes, int offset, int len) throws IOException; native int read (byte[] bytes, int offset, int len) throws IOException;
......
...@@ -96,15 +96,17 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -96,15 +96,17 @@ public class RandomAccessFile implements DataOutput, DataInput
/** /**
* This method initializes a new instance of <code>RandomAccessFile</code> * This method initializes a new instance of <code>RandomAccessFile</code>
* to read from the specified file name with the specified access mode. * 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 * The access mode is either "r" for read only access, "rw" for read
* write access. * 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> * <p>
* Note that a <code>SecurityManager</code> check is made prior to * Note that a <code>SecurityManager</code> check is made prior to
* opening the file to determine whether or not this file is allowed to * opening the file to determine whether or not this file is allowed to
* be read or written. * be read or written.
* *
* @param fileName The name of the file to read and/or write * @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 * @exception IllegalArgumentException If <code>mode</code> has an
* illegal value * illegal value
...@@ -115,16 +117,21 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -115,16 +117,21 @@ public class RandomAccessFile implements DataOutput, DataInput
public RandomAccessFile (String fileName, String mode) public RandomAccessFile (String fileName, String mode)
throws FileNotFoundException throws FileNotFoundException
{ {
// Check the mode
if (!mode.equals("r") && !mode.equals("rw") && !mode.equals("rws") &&
!mode.equals("rwd"))
throw new IllegalArgumentException("Bad mode value: " + mode);
int fdmode; int fdmode;
if (mode.compareTo ("r") == 0) if (mode.equals("r"))
fdmode = FileDescriptor.READ; fdmode = FileDescriptor.READ;
else if (mode.compareTo ("rw") == 0) else if (mode.equals("rw"))
fdmode = FileDescriptor.READ | FileDescriptor.WRITE; fdmode = FileDescriptor.READ | FileDescriptor.WRITE;
else if (mode.equals("rws"))
{
fdmode = (FileDescriptor.READ | FileDescriptor.WRITE
| FileDescriptor.SYNC);
}
else if (mode.equals("rwd"))
{
fdmode = (FileDescriptor.READ | FileDescriptor.WRITE
| FileDescriptor.DSYNC);
}
else else
throw new IllegalArgumentException ("invalid mode: " + mode); throw new IllegalArgumentException ("invalid mode: " + mode);
...@@ -197,9 +204,9 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -197,9 +204,9 @@ public class RandomAccessFile implements DataOutput, DataInput
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
*/ */
public void setLength (long pos) throws IOException public void setLength (long newLen) throws IOException
{ {
fd.setLength(pos); fd.setLength (newLen);
} }
/** /**
...@@ -211,7 +218,7 @@ public class RandomAccessFile implements DataOutput, DataInput ...@@ -211,7 +218,7 @@ public class RandomAccessFile implements DataOutput, DataInput
*/ */
public long length () throws IOException public long length () throws IOException
{ {
return fd.length(); return fd.getLength ();
} }
/** /**
......
...@@ -108,7 +108,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean) ...@@ -108,7 +108,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean)
} }
jlong jlong
java::io::FileDescriptor::length (void) java::io::FileDescriptor::getLength (void)
{ {
return 0; return 0;
} }
......
...@@ -105,6 +105,12 @@ java::io::FileDescriptor::open (jstring path, jint jflags) ...@@ -105,6 +105,12 @@ java::io::FileDescriptor::open (jstring path, jint jflags)
} }
} }
if ((jflags & SYNC))
flags |= O_SYNC;
if ((jflags & DSYNC))
flags |= O_DSYNC;
int fd = ::open (buf, flags, mode); int fd = ::open (buf, flags, mode);
if (fd == -1 && errno == EMFILE) if (fd == -1 && errno == EMFILE)
{ {
...@@ -233,7 +239,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc) ...@@ -233,7 +239,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc)
if (eof_trunc) if (eof_trunc)
{ {
jlong len = length (); jlong len = getLength ();
if (whence == SET) if (whence == SET)
{ {
if (pos > len) if (pos > len)
...@@ -258,7 +264,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc) ...@@ -258,7 +264,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc)
} }
jlong jlong
java::io::FileDescriptor::length (void) java::io::FileDescriptor::getLength (void)
{ {
struct stat sb; struct stat sb;
if (::fstat (fd, &sb)) if (::fstat (fd, &sb))
......
...@@ -244,7 +244,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc) ...@@ -244,7 +244,7 @@ java::io::FileDescriptor::seek (jlong pos, jint whence, jboolean eof_trunc)
{ {
JvAssert (whence == SET || whence == CUR); JvAssert (whence == SET || whence == CUR);
jlong len = length(); jlong len = getLength();
jlong here = getFilePointer(); jlong here = getFilePointer();
if (eof_trunc if (eof_trunc
...@@ -272,7 +272,7 @@ java::io::FileDescriptor::getFilePointer(void) ...@@ -272,7 +272,7 @@ java::io::FileDescriptor::getFilePointer(void)
} }
jlong jlong
java::io::FileDescriptor::length(void) java::io::FileDescriptor::getLength(void)
{ {
DWORD high; DWORD high;
DWORD low; DWORD low;
...@@ -336,5 +336,5 @@ jint ...@@ -336,5 +336,5 @@ jint
java::io::FileDescriptor::available(void) java::io::FileDescriptor::available(void)
{ {
// FIXME: // FIXME:
return length() - getFilePointer(); return getLength() - getFilePointer();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment