This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: java.io.FileDescriptor - API merging with classpath
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 7 May 2003 11:59:17 +0200
- Subject: Patch: java.io.FileDescriptor - API merging with classpath
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello list,
I would like to commit the attached patch to trunk to make
java.io.FileDescriptor similiar in its use to the one of classpath.
This patch does basically two things in FileDescriptor:
1) It introduces two new constants for opening files: SYNC and DSYNC.
They are the Java pendants to O_SYNC and O_DSYNC. Its use is
implemented in native implementation of open(). Further this patch
makes use of this in java.io.RandomAccessFile.
2) It changes the name of length() to getLength().
Any comments ? Okay to commit ?
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+uNj2WSOgCCdjSDsRArnWAJsFPIsxYtN0+9y8Ta6Er2sxPbFWQwCaA7cL
NFRe5vacHJkIQm4erysfofA=
=uhJe
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1876
diff -u -b -B -r1.1876 ChangeLog
--- ChangeLog 6 May 2003 10:07:28 -0000 1.1876
+++ ChangeLog 7 May 2003 09:52:18 -0000
@@ -1,3 +1,28 @@
+2003-05-07 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-06 Michael Koch <konqueror@gmx.de>
* java/io/DataOutputStream.java
Index: gnu/java/nio/natFileChannelImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/natFileChannelImpl.cc,v
retrieving revision 1.4
diff -u -b -B -r1.4 natFileChannelImpl.cc
--- gnu/java/nio/natFileChannelImpl.cc 2 May 2003 05:35:57 -0000 1.4
+++ gnu/java/nio/natFileChannelImpl.cc 7 May 2003 09:52:18 -0000
@@ -34,7 +34,7 @@
jlong
gnu::java::nio::FileChannelImpl::size ()
{
- return fd->length ();
+ return fd->getLength ();
}
jlong
Index: java/io/FileDescriptor.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/FileDescriptor.java,v
retrieving revision 1.12
diff -u -b -B -r1.12 FileDescriptor.java
--- java/io/FileDescriptor.java 28 Mar 2003 09:49:44 -0000 1.12
+++ java/io/FileDescriptor.java 7 May 2003 09:52:18 -0000
@@ -44,6 +44,8 @@
static final int APPEND = 4;
// EXCL is used only when making a temp file.
static final int EXCL = 8;
+ static final int SYNC = 16;
+ static final int DSYNC = 32;
// These are WHENCE values for seek.
static final int SET = 0;
@@ -71,7 +73,7 @@
// past the end is ok (and if a subsequent write occurs the file
// will grow).
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 int read () throws IOException;
native int read (byte[] bytes, int offset, int len) throws IOException;
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/RandomAccessFile.java,v
retrieving revision 1.14
diff -u -b -B -r1.14 RandomAccessFile.java
--- java/io/RandomAccessFile.java 31 Mar 2003 10:15:48 -0000 1.14
+++ java/io/RandomAccessFile.java 7 May 2003 09:52:19 -0000
@@ -96,15 +96,17 @@
/**
* 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
@@ -115,16 +117,21 @@
public RandomAccessFile (String fileName, String mode)
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;
- if (mode.compareTo ("r") == 0)
+ if (mode.equals("r"))
fdmode = FileDescriptor.READ;
- else if (mode.compareTo ("rw") == 0)
+ else if (mode.equals("rw"))
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
throw new IllegalArgumentException ("invalid mode: " + mode);
@@ -197,9 +204,9 @@
*
* @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 long length () throws IOException
{
- return fd.length();
+ return fd.getLength ();
}
/**
Index: java/io/natFileDescriptorEcos.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFileDescriptorEcos.cc,v
retrieving revision 1.9
diff -u -b -B -r1.9 natFileDescriptorEcos.cc
--- java/io/natFileDescriptorEcos.cc 24 Jul 2002 17:48:41 -0000 1.9
+++ java/io/natFileDescriptorEcos.cc 7 May 2003 09:52:19 -0000
@@ -108,7 +108,7 @@
}
jlong
-java::io::FileDescriptor::length (void)
+java::io::FileDescriptor::getLength (void)
{
return 0;
}
Index: java/io/natFileDescriptorPosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.25
diff -u -b -B -r1.25 natFileDescriptorPosix.cc
--- java/io/natFileDescriptorPosix.cc 9 Mar 2003 22:50:02 -0000 1.25
+++ java/io/natFileDescriptorPosix.cc 7 May 2003 09:52:19 -0000
@@ -105,6 +105,12 @@
}
}
+ if ((jflags & SYNC))
+ flags |= O_SYNC;
+
+ if ((jflags & DSYNC))
+ flags |= O_DSYNC;
+
int fd = ::open (buf, flags, mode);
if (fd == -1 && errno == EMFILE)
{
@@ -233,7 +239,7 @@
if (eof_trunc)
{
- jlong len = length ();
+ jlong len = getLength ();
if (whence == SET)
{
if (pos > len)
@@ -258,7 +264,7 @@
}
jlong
-java::io::FileDescriptor::length (void)
+java::io::FileDescriptor::getLength (void)
{
struct stat sb;
if (::fstat (fd, &sb))
Index: java/io/natFileDescriptorWin32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/natFileDescriptorWin32.cc,v
retrieving revision 1.12
diff -u -b -B -r1.12 natFileDescriptorWin32.cc
--- java/io/natFileDescriptorWin32.cc 11 Feb 2003 20:55:26 -0000 1.12
+++ java/io/natFileDescriptorWin32.cc 7 May 2003 09:52:19 -0000
@@ -244,7 +244,7 @@
{
JvAssert (whence == SET || whence == CUR);
- jlong len = length();
+ jlong len = getLength();
jlong here = getFilePointer();
if (eof_trunc
@@ -272,7 +272,7 @@
}
jlong
-java::io::FileDescriptor::length(void)
+java::io::FileDescriptor::getLength(void)
{
DWORD high;
DWORD low;
@@ -336,5 +336,5 @@
java::io::FileDescriptor::available(void)
{
// FIXME:
- return length() - getFilePointer();
+ return getLength() - getFilePointer();
}