From a339cb5bd9cc8a2fc232055dd5f8a1f9f45f093c Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Sun, 2 Mar 2003 15:57:13 +0000 Subject: [PATCH] 2003-03-02 Michael Koch * gnu/java/nio/FileChannelImpl.java (fd): Type FileDescriptor instead of int. (lengthInternal): Removed. (FileChannelImpl): Fixed arguments, check type of file object. (size): Made it native. (implPosition): New native method. (implTruncate): New native method. (position): Implemented. (truncate): Implemented. (nio_mmap_file): Changed arguments. (nio_munmap_file): Changed arguments. (nio_msync): Changed arguments. * gnu/java/nio/natFileChannelImpl.cc (lengthInternal): Removed. (size): New method. (implPosition): New method. (implTruncate): New method. (nio_mmap_file): Changed arguments. (nio_munmap_file): Changed arguments. (nio_msync): Changed arguments. From-SVN: r63668 --- libjava/ChangeLog | 23 +++++++ libjava/gnu/java/nio/FileChannelImpl.java | 75 +++++++++++----------- libjava/gnu/java/nio/natFileChannelImpl.cc | 31 +++++++-- 3 files changed, 85 insertions(+), 44 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 4f3af596055..7d8c17bf9d1 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,26 @@ +2003-03-02 Michael Koch + + * gnu/java/nio/FileChannelImpl.java + (fd): Type FileDescriptor instead of int. + (lengthInternal): Removed. + (FileChannelImpl): Fixed arguments, check type of file object. + (size): Made it native. + (implPosition): New native method. + (implTruncate): New native method. + (position): Implemented. + (truncate): Implemented. + (nio_mmap_file): Changed arguments. + (nio_munmap_file): Changed arguments. + (nio_msync): Changed arguments. + * gnu/java/nio/natFileChannelImpl.cc + (lengthInternal): Removed. + (size): New method. + (implPosition): New method. + (implTruncate): New method. + (nio_mmap_file): Changed arguments. + (nio_munmap_file): Changed arguments. + (nio_msync): Changed arguments. + 2003-03-02 Michael Koch * java/awt/dnd/DropTargetContext.java: diff --git a/libjava/gnu/java/nio/FileChannelImpl.java b/libjava/gnu/java/nio/FileChannelImpl.java index 31779bbc64e..22835401816 100644 --- a/libjava/gnu/java/nio/FileChannelImpl.java +++ b/libjava/gnu/java/nio/FileChannelImpl.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.nio; import java.io.EOFException; +import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -64,41 +65,41 @@ public class FileChannelImpl extends FileChannel { public long address; public int length; - public int fd; + public FileDescriptor fd; public MappedByteBuffer buf; public Object file_obj; // just to keep it live... - /** - * This method came from java.io.RandomAccessFile - * It is private there so we will repeat it here. - */ - private native long lengthInternal (int native_fd) throws IOException; - - public FileChannelImpl (int fd, Object obj) + public FileChannelImpl (FileDescriptor fd, boolean write, Object obj) { + if (!(obj instanceof RandomAccessFile) + && !(obj instanceof FileInputStream) + && !(obj instanceof FileOutputStream)) + throw new InternalError (); + this.fd = fd; this.file_obj = obj; } - public long size () throws IOException - { - if (!isOpen ()) - throw new ClosedChannelException (); + private native long implPosition (); + private native FileChannel implPosition (long newPosition); + private native FileChannel implTruncate (long size); + + private native long nio_mmap_file (long pos, long size, int mode); + private native void nio_unmmap_file (long address, int size); + private native void nio_msync (long address, int length); - return lengthInternal (fd); - } + public native long size () throws IOException; protected void implCloseChannel() throws IOException { + // FIXME + if (address != 0) { - nio_unmmap_file (fd, address, (int) length); + //nio_unmmap_file (fd, address, (int) length); address = 0; } - // FIXME - fd = 0; - if (file_obj instanceof RandomAccessFile) { RandomAccessFile o = (RandomAccessFile) file_obj; @@ -121,14 +122,14 @@ public class FileChannelImpl extends FileChannel int s = (int)size(); if (buf == null) - { + { throw new EOFException("file not mapped"); - } + } for (int i=0; i +#include #include #include jlong -gnu::java::nio::FileChannelImpl::lengthInternal (jint fd) +gnu::java::nio::FileChannelImpl::size () { - throw new ::java::io::IOException (JvNewStringUTF ("lengthInternal not implemented")); + return fd->length (); } jlong -gnu::java::nio::FileChannelImpl::nio_mmap_file (jint, jlong, jint, jint) +gnu::java::nio::FileChannelImpl::implPosition () +{ + return fd->getFilePointer (); +} + +java::nio::channels::FileChannel* +gnu::java::nio::FileChannelImpl::implPosition (jlong newPosition) +{ + fd->seek (newPosition, ::java::io::FileDescriptor::SET, true); + return this; +} + +java::nio::channels::FileChannel* +gnu::java::nio::FileChannelImpl::implTruncate (jlong size) +{ + fd->setLength (size); + return this; +} + +jlong +gnu::java::nio::FileChannelImpl::nio_mmap_file (jlong, jlong, jint) { throw new ::java::io::IOException (JvNewStringUTF ("mmap not implemented")); } void -gnu::java::nio::FileChannelImpl::nio_unmmap_file (jint, jlong, jint) +gnu::java::nio::FileChannelImpl::nio_unmmap_file (jlong, jint) { throw new ::java::io::IOException (JvNewStringUTF ("munmap not implemented")); } void -gnu::java::nio::FileChannelImpl::nio_msync (jint, jlong, jint) +gnu::java::nio::FileChannelImpl::nio_msync (jlong, jint) { throw new ::java::io::IOException (JvNewStringUTF ("msync not implemented")); }