Commit f3b43865 by Tom Tromey Committed by Tom Tromey

PipedReader.java (ready): Throw IOException if pipe closed.

	* java/io/PipedReader.java (ready): Throw IOException if pipe
	closed.
	* java/io/FilterReader.java (close): Don't clear `in'.
	* java/io/CharArrayReader.java (mark): Throw IOException if stream
	closed.
	(read, ready, reset, skip): Added exception message.
	* java/io/BufferedReader.java (mark, reset, ready, read, skip):
	Perform checkStatus check inside synchronized block.

From-SVN: r39641
parent 967eb03e
2001-02-13 Tom Tromey <tromey@redhat.com> 2001-02-13 Tom Tromey <tromey@redhat.com>
* java/io/PipedReader.java (ready): Throw IOException if pipe
closed.
* java/io/FilterReader.java (close): Don't clear `in'.
* java/io/CharArrayReader.java (mark): Throw IOException if stream
closed.
(read, ready, reset, skip): Added exception message.
* java/io/BufferedReader.java (mark, reset, ready, read, skip):
Perform checkStatus check inside synchronized block.
2001-02-13 Tom Tromey <tromey@redhat.com>
* gnu/awt/j2d/AbstractGraphicsState.java (clone): Made public. * gnu/awt/j2d/AbstractGraphicsState.java (clone): Made public.
2001-02-13 Tom Tromey <tromey@redhat.com> 2001-02-13 Tom Tromey <tromey@redhat.com>
......
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -128,9 +128,9 @@ public class BufferedReader extends Reader ...@@ -128,9 +128,9 @@ public class BufferedReader extends Reader
*/ */
public void mark(int readLimit) throws IOException public void mark(int readLimit) throws IOException
{ {
checkStatus();
synchronized (lock) synchronized (lock)
{ {
checkStatus();
// In this method we need to be aware of the special case where // In this method we need to be aware of the special case where
// pos + 1 == limit. This indicates that a '\r' was the last char // pos + 1 == limit. This indicates that a '\r' was the last char
// in the buffer during a readLine. We'll want to maintain that // in the buffer during a readLine. We'll want to maintain that
...@@ -185,9 +185,9 @@ public class BufferedReader extends Reader ...@@ -185,9 +185,9 @@ public class BufferedReader extends Reader
*/ */
public void reset() throws IOException public void reset() throws IOException
{ {
checkStatus();
synchronized (lock) synchronized (lock)
{ {
checkStatus();
if (markPos < 0) if (markPos < 0)
throw new IOException("mark never set or invalidated"); throw new IOException("mark never set or invalidated");
...@@ -215,9 +215,9 @@ public class BufferedReader extends Reader ...@@ -215,9 +215,9 @@ public class BufferedReader extends Reader
*/ */
public boolean ready() throws IOException public boolean ready() throws IOException
{ {
checkStatus();
synchronized (lock) synchronized (lock)
{ {
checkStatus();
return pos < limit || in.ready(); return pos < limit || in.ready();
} }
} }
...@@ -242,9 +242,9 @@ public class BufferedReader extends Reader ...@@ -242,9 +242,9 @@ public class BufferedReader extends Reader
*/ */
public int read(char[] buf, int offset, int count) throws IOException public int read(char[] buf, int offset, int count) throws IOException
{ {
checkStatus();
synchronized (lock) synchronized (lock)
{ {
checkStatus();
// Once again, we need to handle the special case of a readLine // Once again, we need to handle the special case of a readLine
// that has a '\r' at the end of the buffer. In this case, we'll // that has a '\r' at the end of the buffer. In this case, we'll
// need to skip a '\n' if it is the next char to be read. // need to skip a '\n' if it is the next char to be read.
...@@ -329,9 +329,9 @@ public class BufferedReader extends Reader ...@@ -329,9 +329,9 @@ public class BufferedReader extends Reader
public int read() throws IOException public int read() throws IOException
{ {
checkStatus();
synchronized (lock) synchronized (lock)
{ {
checkStatus();
if (pos >= limit && fill () <= 0) if (pos >= limit && fill () <= 0)
return -1; return -1;
return buffer[pos++]; return buffer[pos++];
...@@ -444,11 +444,11 @@ public class BufferedReader extends Reader ...@@ -444,11 +444,11 @@ public class BufferedReader extends Reader
*/ */
public long skip(long count) throws IOException public long skip(long count) throws IOException
{ {
checkStatus();
if (count <= 0)
return 0;
synchronized (lock) synchronized (lock)
{ {
checkStatus();
if (count <= 0)
return 0;
// Yet again, we need to handle the special case of a readLine // Yet again, we need to handle the special case of a readLine
// that has a '\r' at the end of the buffer. In this case, we need // that has a '\r' at the end of the buffer. In this case, we need
// to ignore a '\n' if it is the next char to be read. // to ignore a '\n' if it is the next char to be read.
......
/* Copyright (C) 1998, 1999 Free Software Foundation /* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -63,10 +63,12 @@ public class CharArrayReader extends Reader ...@@ -63,10 +63,12 @@ public class CharArrayReader extends Reader
} }
} }
public void mark(int readAheadLimit) public void mark(int readAheadLimit) throws IOException
{ {
synchronized (lock) synchronized (lock)
{ {
if (buf == null)
throw new IOException("Stream closed");
// readAheadLimit is ignored per Java Class Lib. book, p. 318. // readAheadLimit is ignored per Java Class Lib. book, p. 318.
markedPos = pos; markedPos = pos;
} }
...@@ -82,7 +84,7 @@ public class CharArrayReader extends Reader ...@@ -82,7 +84,7 @@ public class CharArrayReader extends Reader
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
throw new IOException(); throw new IOException("Stream closed");
if (pos < 0) if (pos < 0)
throw new ArrayIndexOutOfBoundsException(pos); throw new ArrayIndexOutOfBoundsException(pos);
...@@ -98,7 +100,7 @@ public class CharArrayReader extends Reader ...@@ -98,7 +100,7 @@ public class CharArrayReader extends Reader
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
throw new IOException(); throw new IOException("Stream closed");
/* Don't need to check pos value, arraycopy will check it. */ /* Don't need to check pos value, arraycopy will check it. */
if (off < 0 || len < 0 || off + len > b.length) if (off < 0 || len < 0 || off + len > b.length)
...@@ -117,7 +119,7 @@ public class CharArrayReader extends Reader ...@@ -117,7 +119,7 @@ public class CharArrayReader extends Reader
public boolean ready() throws IOException public boolean ready() throws IOException
{ {
if (buf == null) if (buf == null)
throw new IOException(); throw new IOException("Stream closed");
return true; return true;
} }
...@@ -127,7 +129,7 @@ public class CharArrayReader extends Reader ...@@ -127,7 +129,7 @@ public class CharArrayReader extends Reader
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
throw new IOException(); throw new IOException("Stream closed");
pos = markedPos; pos = markedPos;
} }
...@@ -138,7 +140,7 @@ public class CharArrayReader extends Reader ...@@ -138,7 +140,7 @@ public class CharArrayReader extends Reader
synchronized (lock) synchronized (lock)
{ {
if (buf == null) if (buf == null)
throw new IOException(); throw new IOException("Stream closed");
// Even though the var numChars is a long, in reality it can never // Even though the var numChars is a long, in reality it can never
// be larger than an int since the result of subtracting 2 positive // be larger than an int since the result of subtracting 2 positive
......
/* Copyright (C) 1998, 1999 Free Software Foundation /* Copyright (C) 1998, 1999, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -31,8 +31,11 @@ public abstract class FilterReader extends Reader ...@@ -31,8 +31,11 @@ public abstract class FilterReader extends Reader
public void close() throws IOException public void close() throws IOException
{ {
// We used to set `in = null' here. We don't, though, because
// that is the simplest way to ensure that read-after-close will
// throw the appropriate exception -- we rely on the filtered
// stream to do it.
in.close(); in.close();
in = null;
} }
public synchronized void mark(int readlimit) throws IOException public synchronized void mark(int readlimit) throws IOException
......
...@@ -312,10 +312,15 @@ public class PipedReader extends Reader ...@@ -312,10 +312,15 @@ public class PipedReader extends Reader
public boolean ready() throws IOException public boolean ready() throws IOException
{ {
// The JDK 1.3 implementation does not appear to check for the closed or // The JDK 1.3 implementation does not appear to check for the closed or
// unconnected stream conditions here. // unconnected stream conditions here. However, checking for a
// closed stream is explicitly required by the JDK 1.2 and 1.3
// documentation (for Reader.close()), so we do it.
synchronized (lock) synchronized (lock)
{ {
if (closed)
throw new IOException("Pipe closed");
if (in < 0) if (in < 0)
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment