]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2005-04-29 Dalibor Topic <robilad@kaffe.org>
authorDalibor Topic <robilad@kaffe.org>
Fri, 29 Apr 2005 18:47:42 +0000 (18:47 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Fri, 29 Apr 2005 18:47:42 +0000 (18:47 +0000)
* java/nio/channels/FileChannelImpl.java
(FileChannelImpl(String, int)): Removed.
(FileChannelImpl(File, int)): Added. Check if opened file is a
directory.
* java/io/FileInputStream.java(FileInputStream): Fixed javadocs.
Call FileChannelImpl(File, int).
* java/io/FileOutputStream.java (FileInputStream): Call
FileChannelImpl(File, int).
* java/io/RandomAccessFile.java (RandomAccessFile):
Call FileChannelImpl(File, int). Switched constructors around.

From-SVN: r99011

libjava/ChangeLog
libjava/gnu/java/nio/channels/FileChannelImpl.java
libjava/java/io/FileInputStream.java
libjava/java/io/FileOutputStream.java
libjava/java/io/RandomAccessFile.java

index 68bee9172f054acbb06edb9ea46230d8d17db087..5a8022eecf81b4bf025ec80f21bc2ede4d72ac8d 100644 (file)
@@ -1,3 +1,16 @@
+2005-04-29  Dalibor Topic  <robilad@kaffe.org>
+
+       * java/nio/channels/FileChannelImpl.java
+       (FileChannelImpl(String, int)): Removed.
+       (FileChannelImpl(File, int)): Added. Check if opened file is a
+       directory.
+       * java/io/FileInputStream.java(FileInputStream): Fixed javadocs.
+       Call FileChannelImpl(File, int).
+       * java/io/FileOutputStream.java (FileInputStream): Call
+       FileChannelImpl(File, int).
+       * java/io/RandomAccessFile.java (RandomAccessFile):
+       Call FileChannelImpl(File, int). Switched constructors around.
+
 2005-04-27  Andrew Haley  <aph@redhat.com>
 
        PR java/19285
index 9d978c923f7175e6fa2f053618b8148dc949c849..aaa4c26086474d5f695a356e685b06f80abac53d 100644 (file)
@@ -41,6 +41,7 @@ package gnu.java.nio.channels;
 import gnu.classpath.Configuration;
 import gnu.java.nio.FileLockImpl;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -102,10 +103,27 @@ public final class FileChannelImpl extends FileChannel
   }
 
   /* Open a file.  MODE is a combination of the above mode flags. */
-  public FileChannelImpl (String path, int mode) throws FileNotFoundException
+  public FileChannelImpl (File file, int mode) throws FileNotFoundException
   {
+    final String path = file.getPath();
     fd = open (path, mode);
     this.mode = mode;
+
+    // First open the file and then check if it is a a directory
+    // to avoid race condition.
+    if (file.isDirectory())
+      {
+       try 
+         {
+             close();
+         }
+       catch (IOException e)
+         {
+             /* ignore it */
+         }
+
+       throw new FileNotFoundException(path + " is a directory");
+      }
   }
 
   /* Used by init() (native code) */
index ebd5d20ad4648d56a71f40acb8d72406edc4cfb3..c719955434f698f1eb57ebc4708e0ad631d91695 100644 (file)
@@ -76,7 +76,8 @@ public class FileInputStream extends InputStream
    * @param name The name of the file this stream should read from
    *
    * @exception SecurityException If read access to the file is not allowed
-   * @exception FileNotFoundException If the file does not exist.
+   * @exception FileNotFoundException If the file does not exist 
+   * or if it is a directory
    */
   public FileInputStream(String name) throws FileNotFoundException
   {
@@ -97,7 +98,8 @@ public class FileInputStream extends InputStream
    * @param file The <code>File</code> object this stream should read from
    *
    * @exception SecurityException If read access to the file is not allowed
-   * @exception FileNotFoundException If the file does not exist.
+   * @exception FileNotFoundException If the file does not exist
+   * or if it is a directory.
    */
   public FileInputStream(File file) throws FileNotFoundException
   {
@@ -105,7 +107,7 @@ public class FileInputStream extends InputStream
     if (s != null)
       s.checkRead(file.getPath());
 
-    ch = new FileChannelImpl (file.getPath(), FileChannelImpl.READ);
+    ch = new FileChannelImpl (file, FileChannelImpl.READ);
   }
 
   /**
index d5fa2d3bb99ce80e357150ddad58639a50a4bf92..e8784429e63a0da628dbb0ac21af4e00a8a1a100 100644 (file)
@@ -155,10 +155,10 @@ public class FileOutputStream extends OutputStream
     if (s != null)
       s.checkWrite(file.getPath());
 
-    ch = new FileChannelImpl (file.getPath(), (append
-                                    ? FileChannelImpl.WRITE
-                                    | FileChannelImpl.APPEND
-                                    : FileChannelImpl.WRITE));
+   ch = new FileChannelImpl (file, (append
+                                   ? FileChannelImpl.WRITE
+                                   | FileChannelImpl.APPEND
+                                   : FileChannelImpl.WRITE));
   }
 
   /**
index c23ca3adf2e8681a2e19578eb5154a0a7afa3429..ef367949a24c8b8c06fe8a14c0e5325cf3c4f6c1 100644 (file)
@@ -86,37 +86,11 @@ public class RandomAccessFile implements DataOutput, DataInput
    * illegal value
    * @exception SecurityException If the requested access to the file 
    * is not allowed
-   * @exception IOException If any other error occurs
+   * @exception FileNotFoundException If the file is a directory, or 
+   * any other error occurs
    */
   public RandomAccessFile (File file, String mode)
     throws FileNotFoundException
-  {
-    this (file.getPath(), mode);
-  }
-
-  /**
-   * 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, "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", "rw", "rws", or "rwd"
-   *
-   * @exception IllegalArgumentException If <code>mode</code> has an 
-   * illegal value
-   * @exception SecurityException If the requested access to the file 
-   * is not allowed
-   * @exception FileNotFoundException If any other error occurs
-   */
-  public RandomAccessFile (String fileName, String mode)
-    throws FileNotFoundException
   {
     int fdmode;
     if (mode.equals("r"))
@@ -136,6 +110,8 @@ public class RandomAccessFile implements DataOutput, DataInput
     else
       throw new IllegalArgumentException ("invalid mode: " + mode);
 
+    final String fileName = file.getPath();
+
     // The obligatory SecurityManager stuff
     SecurityManager s = System.getSecurityManager();
     if (s != null)
@@ -146,12 +122,40 @@ public class RandomAccessFile implements DataOutput, DataInput
           s.checkWrite(fileName);
       }
 
-    ch = new FileChannelImpl (fileName, fdmode);
+    ch = new FileChannelImpl (file, fdmode);
     fd = new FileDescriptor(ch);
     out = new DataOutputStream (new FileOutputStream (fd));
     in = new DataInputStream (new FileInputStream (fd));
   }
 
+  /**
+   * 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, "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", "rw", "rws", or "rwd"
+   *
+   * @exception IllegalArgumentException If <code>mode</code> has an 
+   * illegal value
+   * @exception SecurityException If the requested access to the file 
+   * is not allowed
+   * @exception FileNotFoundException If the file is a directory or 
+   * any other error occurs
+   */
+  public RandomAccessFile (String fileName, String mode)
+    throws FileNotFoundException
+  {
+    this (new File(fileName), mode);
+  }
+
   /**
    * This method closes the file and frees up all file related system
    * resources.  Since most operating systems put a limit on how many files