diff options
author | Michael Koch <konqueror@gmx.de> | 2003-03-28 08:39:15 +0000 |
---|---|---|
committer | Michael Koch <konqueror@gmx.de> | 2003-03-28 08:39:15 +0000 |
commit | 801954f14f59d404aa46f71853ae192af0e5005f (patch) | |
tree | b01a8128a4c9d06f8e48d5d256ca24f56dae7be5 /java/io/FileOutputStream.java | |
parent | fba5e53b877bb1cc32e6cd27eefc2ae355fd3241 (diff) | |
download | classpath-801954f14f59d404aa46f71853ae192af0e5005f.tar.gz |
2003-03-28 Michael Koch <konqueror@gmx.de>
* java/io/File.java:
Merged authors with libgcj, reformatted.
* java/io/FileOutputStream.java:
Merged authors with libgcj, reformatted.
(FileOutputStream): Partly merged with libgcj.
(finalize): New dummy method to make API complete.
(write): Added argument check from libgcj.
* java/io/RandomAccessFile.java:
Merged authors with libgcj, reformatted.
(read*): Throws only IOException.
Diffstat (limited to 'java/io/FileOutputStream.java')
-rw-r--r-- | java/io/FileOutputStream.java | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/java/io/FileOutputStream.java b/java/io/FileOutputStream.java index 175b48edf..c8b4b821e 100644 --- a/java/io/FileOutputStream.java +++ b/java/io/FileOutputStream.java @@ -50,7 +50,8 @@ import gnu.java.nio.FileChannelImpl; * This classes allows a stream of data to be written to a disk file or * any open <code>FileDescriptor</code>. * - * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Aaron M. Renn <arenn@urbanophile.com> + * @author Tom Tromey <tromey@cygnus.com> */ public class FileOutputStream extends OutputStream { @@ -77,25 +78,25 @@ public class FileOutputStream extends OutputStream * @exception SecurityException If write access to the file is not allowed * @exception FileNotFoundException If a non-security error occurs */ - public FileOutputStream (String name, boolean append) + public FileOutputStream (String path, boolean append) throws SecurityException, FileNotFoundException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkWrite(name); + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkWrite(path); fd = new FileDescriptor(); try { if (append) - fd.open(name, "a"); + fd.open(path, "a"); else - fd.open(name, "w"); + fd.open(path, "w"); } catch(IOException e) { - throw new FileNotFoundException(name + ": " + e.getMessage()); + throw new FileNotFoundException(path + ": " + e.getMessage()); } } @@ -114,10 +115,10 @@ public class FileOutputStream extends OutputStream * @exception SecurityException If write access to the file is not allowed * @exception FileNotFoundException If a non-security error occurs */ - public - FileOutputStream(String name) throws SecurityException, FileNotFoundException + public FileOutputStream (String path) + throws SecurityException, FileNotFoundException { - this (name, false); + this (path, false); } /** @@ -184,18 +185,25 @@ public class FileOutputStream extends OutputStream * * @exception SecurityException If write access to the file is not allowed */ - public FileOutputStream (FileDescriptor fd) throws SecurityException + public FileOutputStream (FileDescriptor fdObj) + throws SecurityException { // Hmm, no other exception but this one to throw, but if the descriptor // isn't valid, we surely don't have "permission" to write to it. - if (!fd.valid()) + if (!fdObj.valid()) throw new SecurityException("Invalid FileDescriptor"); - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkWrite(fd); + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkWrite(fdObj); + + fd = fdObj; + } - this.fd = fd; + protected void finalize () throws IOException + { + // We don't actually need this, but we include it because it is + // mentioned in the JCL. } /** @@ -233,7 +241,8 @@ public class FileOutputStream extends OutputStream * * @exception IOException If an error occurs */ - public void write(byte[] buf) throws IOException + public void write (byte[] buf) + throws IOException { write (buf, 0, buf.length); } @@ -248,8 +257,14 @@ public class FileOutputStream extends OutputStream * * @exception IOException If an error occurs */ - public void write(byte[] buf, int offset, int len) throws IOException + public void write (byte[] buf, int offset, int len) + throws IOException { + if (offset < 0 + || len < 0 + || offset + len > buf.length) + throw new ArrayIndexOutOfBoundsException (); + fd.write (buf, offset, len); } |