diff options
author | Mark Wielaard <mark@klomp.org> | 2002-11-29 18:41:03 +0000 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2002-11-29 18:41:03 +0000 |
commit | 7d754e43f0120964d1d329cac79393eb5acd056f (patch) | |
tree | c6f096b1eee5d8183c45d8264da00bb25609d36f | |
parent | 206bdb02165b314d8e5addf878b34c20f8604a78 (diff) | |
download | classpath-7d754e43f0120964d1d329cac79393eb5acd056f.tar.gz |
Merge patches from Julian Dolby <dolby@us.ibm.com>
* java/io/File.java (File(File, String)): Only add separator when
dirpath is not a root dir.
(File(String, String)): Call this(File, String).
(File(String)): Remove all trailing separators when not root dir.
(canWrite): Return null when no separator is found in path.
If a directory then check that we can create and delete temp file.
(list): Return null when file not exists or is not a dir.
Return empty array when listInternal returns null.
* java/io/FileInputStream.java(open): Throws FileNotFoundException.
* java/io/FileOutputStream.java (FileOutputStream): Likewise.
(open): Likewise.
* native/jni/java-io/java_io_FileOutputStream.c (open): Likewise.
* native/jni/java-io/javaio.c (_javaio_close): Check that fd != -1.
* THANKYOU: Add Julian Dolby.
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | THANKYOU | 1 | ||||
-rw-r--r-- | java/io/File.java | 51 | ||||
-rw-r--r-- | java/io/FileInputStream.java | 4 | ||||
-rw-r--r-- | java/io/FileOutputStream.java | 22 | ||||
-rw-r--r-- | native/jni/java-io/java_io_FileOutputStream.c | 5 | ||||
-rw-r--r-- | native/jni/java-io/javaio.c | 8 |
7 files changed, 76 insertions, 34 deletions
@@ -1,3 +1,22 @@ +2002-11-29 Mark Wielaard <mark@klomp.org> + + Merge patches from Julian Dolby <dolby@us.ibm.com> + * java/io/File.java (File(File, String)): Only add separator when + dirpath is not a root dir. + (File(String, String)): Call this(File, String). + (File(String)): Remove all trailing separators when not root dir. + (canWrite): Return null when no separator is found in path. + If a directory then check that we can create and delete temp file. + (list): Return null when file not exists or is not a dir. + Return empty array when listInternal returns null. + * java/io/FileInputStream.java(open): Throws FileNotFoundException. + * java/io/FileOutputStream.java (FileOutputStream): Likewise. + (open): Likewise. + * native/jni/java-io/java_io_FileOutputStream.c (open): Likewise. + * native/jni/java-io/javaio.c (_javaio_close): Check that fd != -1. + + * THANKYOU: Add Julian Dolby. + 2002-11-25 Mark Wielaard <mark@klomp.org> * java/util/jar/JarFile.java (manifest): Not final. @@ -12,6 +12,7 @@ Carlos Cavanna (cdcavanna@yahoo.com) Stephen Crawley (crawley@dstc.edu.au) Moses DeJong (dejong@cs.umn.edu) Patrick Doyle (doylep@eecg.toronto.edu) +Julian Dolby (dolby@us.ibm.com) Raimar Falke (hawk@hawk.shef.ac.uk) Philip Fong (pwlfong@users.sourceforge.net) Etienne M. Gagnon (etienne.gagnon@uqam.ca) diff --git a/java/io/File.java b/java/io/File.java index 3e167e721..2886c27f1 100644 --- a/java/io/File.java +++ b/java/io/File.java @@ -281,12 +281,17 @@ File(File directory, String name) { String dirname = System.getProperty("user.dir"); if (dirname == null) - throw new IllegalArgumentException("Cannot determine default user directory"); + throw new IllegalArgumentException + ("Cannot determine default user directory"); directory = new File(dirname); } - path = directory.getPath() + separator + name; + String dirpath = directory.getPath(); + if (PlatformHelper.isRootDirectory(dirpath)) + path = dirpath + name; + else + path = dirpath + separator + name; } /*************************************************************************/ @@ -304,17 +309,9 @@ File(File directory, String name) public File(String dirname, String name) { - this (name); //set path field & check null - if (!isAbsolute ()) - { - if (dirname != null) - { - if (PlatformHelper.endWithSeparator (dirname)) - path = dirname + name; - else - path = dirname + separator + name; - } - } + this( + dirname==null? (File)null: new File(dirname), + name); } /*************************************************************************/ @@ -333,6 +330,10 @@ File(String name) // Per the spec if (path == null) throw new NullPointerException("File name is null"); + + if (!PlatformHelper.isRootDirectory(path)) + while (PlatformHelper.endWithSeparator(path)) + path = PlatformHelper.removeTailSeparator(path); } /*************************************************************************/ @@ -470,8 +471,9 @@ getParent() if (PlatformHelper.isRootDirectory(path)) return null; - String par_path = PlatformHelper.removeTailSeparator(path); - int pos = PlatformHelper.lastIndexOfSeparator(path); + String par_path = path; + + int pos = PlatformHelper.lastIndexOfSeparator(par_path); if (pos == -1) return null; @@ -573,7 +575,18 @@ canWrite() throws SecurityException if (!exists()) return(false); - return(canWriteInternal(path)); + if (!isDirectory()) + return(canWriteInternal(path)); + else + try + { + File test = createTempFile("test-dir-write", null, this); + return (test != null && test.delete()); + } + catch (IOException ioe) + { + return(false); + } } /*************************************************************************/ @@ -1064,10 +1077,14 @@ list(FilenameFilter filter) // Get the list of files String list_path = PlatformHelper.removeTailSeparator(path); + File dir = new File(list_path); + if (! dir.exists() || ! dir.isDirectory() ) return null; + String files[] = listInternal(list_path); + if (files == null) - return(null); + return new String[0]; if (filter == null) return(files); diff --git a/java/io/FileInputStream.java b/java/io/FileInputStream.java index c1cca1462..54645e736 100644 --- a/java/io/FileInputStream.java +++ b/java/io/FileInputStream.java @@ -1,5 +1,5 @@ /* FileInputStream.java -- An input stream that reads from disk files. - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -395,7 +395,7 @@ readInternal(int native_fd, byte[] buf, int offset, int len) throws IOException * * @param name The name of the file to open * - * @exception IOException If an error occurs + * @exception FileNotFoundException If an error occurs */ private native int open(String name) throws FileNotFoundException; diff --git a/java/io/FileOutputStream.java b/java/io/FileOutputStream.java index 9f14c049e..50ee24022 100644 --- a/java/io/FileOutputStream.java +++ b/java/io/FileOutputStream.java @@ -97,10 +97,10 @@ private int native_fd = -1; * @param name The name of the file this stream should write to * * @exception SecurityException If write access to the file is not allowed - * @exception IOException If a non-security error occurs + * @exception FileNotFoundException If a non-security error occurs */ public -FileOutputStream(String name) throws SecurityException, IOException +FileOutputStream(String name) throws SecurityException, FileNotFoundException { this(name, false); } @@ -121,10 +121,10 @@ FileOutputStream(String name) throws SecurityException, IOException * @param file The <code>File</code> object this stream should write to * * @exception SecurityException If write access to the file is not allowed - * @exception IOException If a non-security error occurs + * @exception FileNotFoundException If a non-security error occurs */ public -FileOutputStream(File file) throws SecurityException, IOException +FileOutputStream(File file) throws SecurityException, FileNotFoundException { this(file.getPath(), false); } @@ -144,14 +144,15 @@ FileOutputStream(File file) throws SecurityException, IOException * thrown if writing is not allowed. * * @param name The name of the file this stream should write to - * @param append <code>true</code> to append bytes to the end of the file, or <code>false</code> to write bytes to the beginning + * @param append <code>true</code> to append bytes to the end of the file, + * or <code>false</code> to write bytes to the beginning * * @exception SecurityException If write access to the file is not allowed - * @exception IOException If a non-security error occurs + * @exception FileNotFoundException If a non-security error occurs */ public FileOutputStream(String name, boolean append) throws SecurityException, - IOException + FileNotFoundException { SecurityManager sm = System.getSecurityManager(); if (sm != null) @@ -304,14 +305,15 @@ writeInternal(int native_fd, byte[] buf, int offset, int len) throws IOException * beginning. * * @param name The name of the file to open - * @param append <code>true</code> to write starting at the end of the file, <code>false</code> to start writing at the beginning + * @param append <code>true</code> to write starting at the end of the file, + * <code>false</code> to start writing at the beginning * * @return A native file descriptor for this file * - * @exception IOException If an error occurs + * @exception FileNotFoundException If an error occurs */ private synchronized native int -open(String name, boolean append) throws IOException; +open(String name, boolean append) throws FileNotFoundException; /*************************************************************************/ diff --git a/native/jni/java-io/java_io_FileOutputStream.c b/native/jni/java-io/java_io_FileOutputStream.c index ad2ac6b9a..7ed049520 100644 --- a/native/jni/java-io/java_io_FileOutputStream.c +++ b/native/jni/java-io/java_io_FileOutputStream.c @@ -1,5 +1,5 @@ /* FileOutputStream.c - Native methods for java.io.FileOutputStream class - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -70,7 +70,8 @@ Java_java_io_FileOutputStream_open(JNIEnv *env, jobject obj, jstring name, int rc = lseek(fd, 0, SEEK_END); if (rc == -1) { - JCL_ThrowException(env, "java/io/IOException", strerror(errno)); + JCL_ThrowException(env, "java/io/FileNotFoundException", + strerror(errno)); close(fd); return(-1); } diff --git a/native/jni/java-io/javaio.c b/native/jni/java-io/javaio.c index f942bf338..8f2d280da 100644 --- a/native/jni/java-io/javaio.c +++ b/native/jni/java-io/javaio.c @@ -1,5 +1,5 @@ /* javaio.c - Common java.io native functions - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -88,9 +88,11 @@ _javaio_open(JNIEnv *env, jstring name, int flags) void _javaio_close(JNIEnv *env, jint fd) { - int rc; + int rc = 0; + + if (fd != -1) + rc = close(fd); - rc = close(fd); if (rc == -1) JCL_ThrowException(env, "java/io/IOException", strerror(errno)); } |