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: java.io - java.nio.FileChannel support


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

Hi list,


I wrote a little patch to add java.nio.FileChannel support to java.io.
Please review and comment.

BTW: This doesnt mean java.nio in CVS works.


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

iD8DBQE+YoTIWSOgCCdjSDsRAskFAKCJ3B6wMlmXDrcBL+l45wiIIu6dGgCfR8mo
q1PtJElxCxIC7fGMdougtTQ=
=9SkB
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1761
diff -u -r1.1761 ChangeLog
--- ChangeLog	2 Mar 2003 21:25:59 -0000	1.1761
+++ ChangeLog	2 Mar 2003 22:20:32 -0000
@@ -1,5 +1,18 @@
 2003-03-02  Michael Koch  <konqueror at gmx dot de>
 
+	* java/io/FileInputStream.java
+	(getChannel): New implementation.
+	* java/io/FileOutputStream.java
+	(ch): New member variable.
+	(getChannel): Implemented.
+	* java/io/RandomAccessFile.java
+	(RandomAccessFile): Throws FileNotFoundException instead of
+	IOException.
+	(getChannel): New method.
+	(ch): New member variable.
+
+2003-03-02  Michael Koch  <konqueror at gmx dot de>
+
 	* java/net/NetPermission.java:
 	Merged copyright with classpath.
 
Index: java/io/FileInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/FileInputStream.java,v
retrieving revision 1.9
diff -u -r1.9 FileInputStream.java
--- java/io/FileInputStream.java	4 Jan 2003 00:08:11 -0000	1.9
+++ java/io/FileInputStream.java	2 Mar 2003 22:20:32 -0000
@@ -9,6 +9,7 @@
 package java.io;
 
 import java.nio.channels.FileChannel;
+import gnu.java.nio.FileChannelImpl;
 
 /**
  * @author Warren Levy <warrenl at cygnus dot com>
@@ -99,6 +100,12 @@
 
   public FileChannel getChannel ()
   {
-    return ch;
+    synchronized (this)
+      {
+        if (ch == null)
+          ch = new FileChannelImpl (fd, false, this);
+    
+        return ch;
+      }
   }
 }
Index: java/io/FileOutputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/FileOutputStream.java,v
retrieving revision 1.5
diff -u -r1.5 FileOutputStream.java
--- java/io/FileOutputStream.java	20 Nov 2002 16:19:05 -0000	1.5
+++ java/io/FileOutputStream.java	2 Mar 2003 22:20:32 -0000
@@ -11,6 +11,7 @@
 package java.io;
 
 import java.nio.channels.FileChannel;
+import gnu.java.nio.FileChannelImpl;
 
 /**
  * @author Tom Tromey <tromey at cygnus dot com>
@@ -93,11 +94,18 @@
       fd.close();
   }
 
-  // Instance variables.
-  private FileDescriptor fd;
-
   public FileChannel getChannel ()
   {
-    return null;
+    synchronized (this)
+      {
+        if (ch == null)
+          ch = new FileChannelImpl (fd, true, this);
+
+        return ch;
+      }
   }
+
+  // Instance variables.
+  private FileDescriptor fd;
+  private FileChannel ch;
 }
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/RandomAccessFile.java,v
retrieving revision 1.8
diff -u -r1.8 RandomAccessFile.java
--- java/io/RandomAccessFile.java	13 Aug 2002 23:10:11 -0000	1.8
+++ java/io/RandomAccessFile.java	2 Mar 2003 22:20:32 -0000
@@ -10,6 +10,9 @@
 
 package java.io;
 
+import java.nio.channels.FileChannel;
+import gnu.java.nio.FileChannelImpl;
+
 /**
  * @author Tom Tromey <tromey at cygnus dot com>
  * @date September 25, 1998 
@@ -50,7 +53,8 @@
     return fd.length();
   }
 
-  public RandomAccessFile (String fileName, String mode) throws IOException
+  public RandomAccessFile (String fileName, String mode)
+    throws FileNotFoundException
   {
     int fdmode;
     if (mode.compareTo ("r") == 0)
@@ -73,7 +77,7 @@
     in = new DataInputStream (new FileInputStream (fd));
   }
 
-  public RandomAccessFile (File file, String mode) throws IOException
+  public RandomAccessFile (File file, String mode) throws FileNotFoundException
   {
     this (file.getPath(), mode);
   }
@@ -248,10 +252,21 @@
     out.writeUTF(s);
   }
 
+  public FileChannel getChannel ()
+  {
+    synchronized (this)
+      {
+        if (ch == null)
+          ch = new FileChannelImpl (fd, true, this);
+
+	return ch;
+      }
+  }
 
   // The underlying file.
   private FileDescriptor fd;
   // The corresponding input and output streams.
   private DataOutputStream out;
   private DataInputStream in;
+  private FileChannel ch;
 }

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