diff options
author | Tom Tromey <tromey@redhat.com> | 2001-02-20 19:01:55 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2001-02-20 19:01:55 +0000 |
commit | 39f90b7ce07ffa09df609ec724a22fe18606a668 (patch) | |
tree | bea0be04a6a6d1d16e61e97edbf76650ad68223a /libjava/java/io/BufferedWriter.java | |
parent | c9407e4c671efb42c76dbb80a13ecf0c5dc09f05 (diff) | |
download | gcc-39f90b7ce07ffa09df609ec724a22fe18606a668.zip gcc-39f90b7ce07ffa09df609ec724a22fe18606a668.tar.gz gcc-39f90b7ce07ffa09df609ec724a22fe18606a668.tar.bz2 |
PipedWriter.java (flush): Throw exception if stream closed.
* java/io/PipedWriter.java (flush): Throw exception if stream
closed.
* java/io/OutputStreamWriter.java (write): Throw exception if
stream closed.
(writeChars): Don't throw exception if stream closed.
* java/io/CharArrayWriter.java (closed): New field.
(close): Set it.
(flush): Throw exception if stream closed.
(reset): Synchronize on correct lock. Allow stream to be
reopened.
(toCharArray, toString, writeTo): Synchronize.
(write): Throwe exception if stream closed.
* java/io/BufferedWriter.java (close): Clear `buffer'.
(flush): Throw IOException if stream is closed.
(write): Likewise.
From-SVN: r39927
Diffstat (limited to 'libjava/java/io/BufferedWriter.java')
-rw-r--r-- | libjava/java/io/BufferedWriter.java | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/libjava/java/io/BufferedWriter.java b/libjava/java/io/BufferedWriter.java index f31dc28..e995861 100644 --- a/libjava/java/io/BufferedWriter.java +++ b/libjava/java/io/BufferedWriter.java @@ -1,12 +1,29 @@ -// BufferedWriter.java - Filtered character output stream. +/* BufferedWriter.java -- Buffer output into large blocks before writing + Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. -/* Copyright (C) 1998, 1999, 2000 Free Software Foundation +This file is part of GNU Classpath. - This file is part of libgcj. +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +As a special exception, if you link this library with other files to +produce an executable, this library does not by itself cause the +resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why the +executable file might be covered by the GNU General Public License. */ -This software is copyrighted work licensed under the terms of the -Libgcj License. Please consult the file "LIBGCJ_LICENSE" for -details. */ package java.io; @@ -67,8 +84,14 @@ public class BufferedWriter extends Writer */ public void close () throws IOException { - localFlush (); - out.close(); + synchronized (lock) + { + // It is safe to call localFlush even if the stream is already + // closed. + localFlush (); + out.close(); + buffer = null; + } } /** @@ -79,8 +102,13 @@ public class BufferedWriter extends Writer */ public void flush () throws IOException { - localFlush (); - out.flush(); + synchronized (lock) + { + if (buffer == null) + throw new IOException ("Stream closed"); + localFlush (); + out.flush(); + } } /** @@ -109,6 +137,8 @@ public class BufferedWriter extends Writer { synchronized (lock) { + if (buffer == null) + throw new IOException ("Stream closed"); buffer[count++] = (char) oneChar; if (count == buffer.length) localFlush (); @@ -135,6 +165,9 @@ public class BufferedWriter extends Writer synchronized (lock) { + if (buffer == null) + throw new IOException ("Stream closed"); + // Bypass buffering if there is too much incoming data. if (count + len > buffer.length) { @@ -171,6 +204,9 @@ public class BufferedWriter extends Writer synchronized (lock) { + if (buffer == null) + throw new IOException ("Stream closed"); + if (count + len > buffer.length) { localFlush (); |