This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] gnu.java.nio.FileChannelImpl


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


Here a patch I commited for gnu.java.nio.FileChannelImpl. This class 
doesn't get compiled yet by default but the nigthmare is near ;-)


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+S7YyWSOgCCdjSDsRAkWFAJ9L7k67oYvuWskbSMOQG6YxCeeohwCeJivM
jr9tm8viPRW+v+glMWHv6V0=
=Jztn
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1694
diff -u -r1.1694 ChangeLog
--- ChangeLog	13 Feb 2003 11:37:09 -0000	1.1694
+++ ChangeLog	13 Feb 2003 15:12:00 -0000
@@ -1,3 +1,26 @@
+2003-02-13  Michael  <konqueror@gmx.de>
+
+	* gnu/java/nio/FileChannelImpl.java
+	(lengthInternal): Must be native.
+	(size): Check if channel is already closed.
+	(implCloseChannel): Reformated.
+	(read): w was unused, removed it.
+	(read): Removed.
+	(read): New method.
+	(write): New method.
+	(map): Check arguments.
+	(force): Throws IOException, check if channel is closed.
+	(transferTo): New method.
+	(transferFrom): New method.
+	(lock): New method.
+	(tryLock): New method.
+	(position): New method.
+	(truncate): New method.
+	(nio_mmap_file): Uncommented.
+	(nio_munmap_file): Uncommented.
+	(nio_msync): Uncommented.
+	* gnu/java/nio/natFileChannelImpl.cc: New file.
+	
 2003-02-13  Michael Koch  <konqueror@gmx.de>
 
 	* java/nio/ByteBuffer.java
Index: gnu/java/nio/FileChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/FileChannelImpl.java,v
retrieving revision 1.1
diff -u -r1.1 FileChannelImpl.java
--- gnu/java/nio/FileChannelImpl.java	18 Nov 2002 13:56:58 -0000	1.1
+++ gnu/java/nio/FileChannelImpl.java	13 Feb 2003 15:12:00 -0000
@@ -44,7 +44,13 @@
 import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
+import java.nio.channels.ClosedChannelException;
 import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.NonReadableChannelException;
+import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 
 /**
  * This file is not user visible !
@@ -66,11 +72,7 @@
    * 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;
-  private long lengthInternal (int native_fd) throws IOException
-  {
-    return 0;
-  };
+  private native long lengthInternal (int native_fd) throws IOException;
 
   public FileChannelImpl (int fd, Object obj)
   {
@@ -80,39 +82,42 @@
 
   public long size () throws IOException
   {
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
     return lengthInternal (fd);
   }
     
-  protected void implCloseChannel()  throws IOException
+  protected void implCloseChannel() throws IOException
   {
     if (address != 0)
-	    {
+      {
         nio_unmmap_file (fd, address, (int) length);
-	    }
+        address = 0;
+      }
 
     // FIXME
     fd = 0;
 
     if (file_obj instanceof RandomAccessFile)
-	    {
+      {
         RandomAccessFile o = (RandomAccessFile) file_obj;
         o.close();
-	    }
+      }
     else if (file_obj instanceof FileInputStream)
-	    {
+      {
         FileInputStream o = (FileInputStream) file_obj;
         o.close();
-	    }
+      }
     else if (file_obj instanceof FileOutputStream)
-	    {
+      {
         FileOutputStream o = (FileOutputStream) file_obj;
         o.close();
-	    }
+      }
   }
 
   public int read (ByteBuffer dst) throws IOException
   {
-    int w = 0;
     int s = (int)size();
 
     if (buf == null)
@@ -128,9 +133,18 @@
     return s;
   }
 
-  public long read (ByteBuffer[] dsts) throws IOException
+  public int read (ByteBuffer dst, long position)
+    throws IOException
   {
-    return read (dsts, 0, dsts.length);
+    if (position < 0)
+      throw new IllegalArgumentException ();
+
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+    
+    // FIXME: check for NonReadableChannelException
+
+    throw new Error ("Not implemented");
   }
 
   public long read (ByteBuffer[] dsts, int offset, int length)
@@ -164,6 +178,20 @@
     return w;
   }
     
+  public int write (ByteBuffer src, long position)
+    throws IOException
+  {
+    if (position < 0)
+      throw new IllegalArgumentException ();
+
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+    
+    // FIXME: check for NonWritableChannelException
+
+    throw new Error ("Not implemented");
+  }
+  
   public long write(ByteBuffer[] srcs, int offset, int length)
     throws IOException
   {
@@ -173,13 +201,22 @@
 	    {
         res += write (srcs[i]);
 	    }
-	return res;
-    }
+    
+    return res;
+  }
 				   
   public MappedByteBuffer map (FileChannel.MapMode mode, long position,
                                long size)
     throws IOException
   {
+    if ((mode != MapMode.READ_ONLY
+         && mode != MapMode.READ_WRITE
+         && mode != MapMode.PRIVATE)
+        || position < 0
+        || size < 0
+        || size > Integer.MAX_VALUE)
+      throw new IllegalArgumentException ();
+    
 //     int cmode = mode.m;
 //     address = nio_mmap_file (fd, position, size, cmode);
 //     length = size;
@@ -208,27 +245,113 @@
   /**
    * msync with the disk
    */
-  public void force (boolean metaData)
+  public void force (boolean metaData) throws IOException
   {
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
+    // FIXME: What to do with metaData ?
+    
     nio_msync (fd, address, length);
   }
 
-//   static native long nio_mmap_file (int fd, long pos, int size, int mode);
+  public long transferTo (long position, long count, WritableByteChannel target)
+    throws IOException
+  {
+    if (position < 0
+        || count < 0)
+      throw new IllegalArgumentException ();
+
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
+    // FIXME: check for NonReadableChannelException
+    // FIXME: check for NonWritableChannelException
+    
+    throw new Error ("Not implemented");
+  }
+
+  public long transferFrom (ReadableByteChannel src, long position, long count)
+    throws IOException
+  {
+    if (position < 0
+        || count < 0)
+      throw new IllegalArgumentException ();
 
-//   static native void nio_unmmap_file (int fd, long address, int size);
+    if (!isOpen ())
+      throw new ClosedChannelException ();
 
-//   static native void nio_msync (int fd, long address, int length);
+    // FIXME: check for NonReadableChannelException
+    // FIXME: check for NonWritableChannelException
+    
+    throw new Error ("Not implemented");
+  }
 
-  static long nio_mmap_file (int fd, long pos, int size, int mode)
+  public FileLock lock (long position, long size, boolean shared)
+    throws IOException
   {
-    return 0;
+    if (position < 0
+        || size < 0)
+      throw new IllegalArgumentException ();
+
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
+    // FIXME: check for NonReadableChannelException
+    // FIXME: check for NonWritableChannelException
+    
+    throw new Error ("Not implemented");
   }
+  
+  public FileLock tryLock (long position, long size, boolean shared)
+    throws IOException
+  {
+    if (position < 0
+        || size < 0)
+      throw new IllegalArgumentException ();
+
+    if (!isOpen ())
+      throw new ClosedChannelException ();
 
-  static void nio_unmmap_file (int fd, long address, int size)
+    throw new Error ("Not implemented");
+  }
+
+  public long position ()
+    throws IOException
+  {
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
+    throw new Error ("not implemented");
+  }
+  
+  public FileChannel position (long newPosition)
+    throws IOException
   {
-  };
+    if (newPosition < 0)
+      throw new IllegalArgumentException ();
 
-  static void nio_msync (int fd, long address, int length)
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
+    throw new Error ("not implemented");
+  }
+  
+  public FileChannel truncate (long size)
+    throws IOException
   {
-  };
+    if (size < 0)
+      throw new IllegalArgumentException ();
+
+    if (!isOpen ())
+      throw new ClosedChannelException ();
+
+    // FIXME: check for NonWritableChannelException
+
+    throw new Error ("not implemented");
+  }
+  
+  private static native long nio_mmap_file (int fd, long pos, int size, int mode);
+  private static native void nio_unmmap_file (int fd, long address, int size);
+  private static native void nio_msync (int fd, long address, int length);
 }
Index: gnu/java/nio/natFileChannelImpl.cc
===================================================================
RCS file: gnu/java/nio/natFileChannelImpl.cc
diff -N gnu/java/nio/natFileChannelImpl.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/natFileChannelImpl.cc	13 Feb 2003 15:12:00 -0000
@@ -0,0 +1,53 @@
+// natFileChannelImpl.cc
+
+/* Copyright (C) 2003  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+
+#include <jvm.h>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#include <gnu/java/nio/FileChannelImpl.h>
+#include <java/io/IOException.h>
+#include <java/nio/channels/FileChannel.h>
+
+jlong
+gnu::java::nio::FileChannelImpl::lengthInternal (jint fd)
+{
+  throw new ::java::io::IOException (JvNewStringUTF ("lengthInternal not implemented"));
+}
+
+jlong
+gnu::java::nio::FileChannelImpl::nio_mmap_file (jint, jlong, jint, jint)
+{
+  throw new ::java::io::IOException (JvNewStringUTF ("mmap not implemented"));
+}
+
+void
+gnu::java::nio::FileChannelImpl::nio_unmmap_file (jint, jlong, jint)
+{
+  throw new ::java::io::IOException (JvNewStringUTF ("munmap not implemented"));
+}
+
+void
+gnu::java::nio::FileChannelImpl::nio_msync (jint, jlong, jint)
+{
+  throw new ::java::io::IOException (JvNewStringUTF ("msync not implemented"));
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]