[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Writer subclasses -vs- IOException
From: |
Tom Tromey |
Subject: |
FYI: Writer subclasses -vs- IOException |
Date: |
20 Feb 2001 12:09:15 -0700 |
I'm checking this in. This makes PipedWriter and BufferedWriter
correctly conform to the Writer semantics regarding close().
I didn't check the other Writer subclasses in Classpath. I did for
libgcj, though, so if somebody (maybe me, someday) merges the classes
then presumably this will be fixed then.
2001-02-20 Tom Tromey <address@hidden>
* java/io/PipedWriter.java (flush): Throw exception if stream
closed.
* java/io/BufferedWriter.java (close): Clear `buffer'.
(flush): Throw IOException if stream is closed.
(write): Likewise.
Tom
Index: java/io/BufferedWriter.java
===================================================================
RCS file: /cvs/classpath/java/io/BufferedWriter.java,v
retrieving revision 1.5
diff -u -r1.5 BufferedWriter.java
--- java/io/BufferedWriter.java 2000/05/20 20:32:56 1.5
+++ java/io/BufferedWriter.java 2001/02/20 18:58:31
@@ -84,8 +84,14 @@
*/
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;
+ }
}
/**
@@ -96,8 +102,13 @@
*/
public void flush () throws IOException
{
- localFlush ();
- out.flush();
+ synchronized (lock)
+ {
+ if (buffer == null)
+ throw new IOException ("Stream closed");
+ localFlush ();
+ out.flush();
+ }
}
/**
@@ -126,6 +137,8 @@
{
synchronized (lock)
{
+ if (buffer == null)
+ throw new IOException ("Stream closed");
buffer[count++] = (char) oneChar;
if (count == buffer.length)
localFlush ();
@@ -152,6 +165,9 @@
synchronized (lock)
{
+ if (buffer == null)
+ throw new IOException ("Stream closed");
+
// Bypass buffering if there is too much incoming data.
if (count + len > buffer.length)
{
@@ -188,6 +204,9 @@
synchronized (lock)
{
+ if (buffer == null)
+ throw new IOException ("Stream closed");
+
if (count + len > buffer.length)
{
localFlush ();
Index: java/io/PipedWriter.java
===================================================================
RCS file: /cvs/classpath/java/io/PipedWriter.java,v
retrieving revision 1.4
diff -u -r1.4 PipedWriter.java
--- java/io/PipedWriter.java 2001/01/05 08:22:42 1.4
+++ java/io/PipedWriter.java 2001/02/20 18:58:31
@@ -142,8 +142,10 @@
* had read all available data. Thats not the case - this method
* appears to be a no-op?
*/
- public void flush()
+ public void flush() throws IOException
{
+ if (closed)
+ throw new IOException ("Pipe closed");
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: Writer subclasses -vs- IOException,
Tom Tromey <=