2003-03-20 Michael Koch <konqueror@gmx.de>
authorMichael Koch <konqueror@gmx.de>
Thu, 20 Mar 2003 07:54:24 +0000 (07:54 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Thu, 20 Mar 2003 07:54:24 +0000 (07:54 +0000)
* 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.

From-SVN: r64609

libjava/ChangeLog
libjava/java/io/FileInputStream.java
libjava/java/io/FileOutputStream.java
libjava/java/io/RandomAccessFile.java

index 6c0821ececcf9b4ce8ef9a0b1c6929ad61112ac8..7e3685709923e626010e61fbab3c8c22f233ee6b 100644 (file)
@@ -1,3 +1,16 @@
+2003-03-20  Michael Koch  <konqueror@gmx.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-20  Michael Koch  <konqueror@gmx.de>
 
        * java/io/DataOutputStream.java,
index bbc7f7c68407b14f7ee5d10e008a7dc8801e909a..dcda9d81e64ae2beeb51ecf5ee36614325c6be9d 100644 (file)
@@ -34,6 +34,7 @@ exception statement from your version. */
 package java.io;
 
 import java.nio.channels.FileChannel;
+import gnu.java.nio.FileChannelImpl;
 
 /**
  * @author Warren Levy <warrenl@cygnus.com>
@@ -124,6 +125,12 @@ public class FileInputStream extends InputStream
 
   public FileChannel getChannel ()
   {
-    return ch;
+    synchronized (this)
+      {
+        if (ch == null)
+          ch = new FileChannelImpl (fd, false, this);
+    
+        return ch;
+      }
   }
 }
index 1154a4b2806ba3c9a90d7a96b222c4f91a16b154..eaf4d9beaa258fd889ae669803069a74a3b67e81 100644 (file)
@@ -39,6 +39,7 @@ exception statement from your version. */
 package java.io;
 
 import java.nio.channels.FileChannel;
+import gnu.java.nio.FileChannelImpl;
 
 /**
  * @author Tom Tromey <tromey@cygnus.com>
@@ -147,11 +148,18 @@ public class FileOutputStream extends OutputStream
       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 d0192829e83befecac270f00c0dc67f767a1dcc5..32d26877ed36093a20785a0a7dc2628896a3a200 100644 (file)
@@ -38,6 +38,9 @@ exception statement from your version. */
 
 package java.io;
 
+import java.nio.channels.FileChannel;
+import gnu.java.nio.FileChannelImpl;
+
 /**
  * @author Tom Tromey <tromey@cygnus.com>
  * @date September 25, 1998 
@@ -78,7 +81,8 @@ public class RandomAccessFile implements DataOutput, DataInput
     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)
@@ -101,7 +105,7 @@ public class RandomAccessFile implements DataOutput, DataInput
     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);
   }
@@ -276,10 +280,21 @@ public class RandomAccessFile implements DataOutput, DataInput
     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;
 }