Commit 2c11433f by Michael Koch Committed by Michael Koch

2004-09-27 Michael Koch <konqueror@gmx.de>

	* java/io/BufferedInputStream.java
	(BufferedInputStream): Added Jeroen Frijters to authors.
	(count): Don't explicitely initialize with default value.
	(pos): Likewise.
	(marklimit): Likewise.
	(read): Changed boolean expression to match GNU classpath' version.
	(reset): Add proper message to exception.
	(skip): Check for closed stream.
	(refill): Likewise.

From-SVN: r88167
parent 94c1e7ac
2004-09-27 Michael Koch <konqueror@gmx.de>
* java/io/BufferedInputStream.java
(BufferedInputStream): Added Jeroen Frijters to authors.
(count): Don't explicitely initialize with default value.
(pos): Likewise.
(marklimit): Likewise.
(read): Changed boolean expression to match GNU classpath' version.
(reset): Add proper message to exception.
(skip): Check for closed stream.
(refill): Likewise.
2004-09-26 Per Bothner <per@bothner.com> 2004-09-26 Per Bothner <per@bothner.com>
* prims.cc (unblock_signal): Annotate signum with __unused__ to * prims.cc (unblock_signal): Annotate signum with __unused__ to
......
...@@ -61,6 +61,7 @@ package java.io; ...@@ -61,6 +61,7 @@ package java.io;
* *
* @author Aaron M. Renn (arenn@urbanophile.com) * @author Aaron M. Renn (arenn@urbanophile.com)
* @author Warren Levy <warrenl@cygnus.com> * @author Warren Levy <warrenl@cygnus.com>
* @author Jeroen Frijters <jeroen@frijters.net>
*/ */
public class BufferedInputStream extends FilterInputStream public class BufferedInputStream extends FilterInputStream
{ {
...@@ -79,13 +80,13 @@ public class BufferedInputStream extends FilterInputStream ...@@ -79,13 +80,13 @@ public class BufferedInputStream extends FilterInputStream
* The number of valid bytes currently in the buffer. It is also the index * The number of valid bytes currently in the buffer. It is also the index
* of the buffer position one byte past the end of the valid data. * of the buffer position one byte past the end of the valid data.
*/ */
protected int count = 0; protected int count;
/** /**
* The index of the next character that will by read from the buffer. * The index of the next character that will by read from the buffer.
* When <code>pos == count</code>, the buffer is empty. * When <code>pos == count</code>, the buffer is empty.
*/ */
protected int pos = 0; protected int pos;
/** /**
* The value of <code>pos</code> when the <code>mark()</code> method was * The value of <code>pos</code> when the <code>mark()</code> method was
...@@ -100,7 +101,7 @@ public class BufferedInputStream extends FilterInputStream ...@@ -100,7 +101,7 @@ public class BufferedInputStream extends FilterInputStream
* After this may bytes are read, the <code>reset()</code> method * After this may bytes are read, the <code>reset()</code> method
* may not be called successfully. * may not be called successfully.
*/ */
protected int marklimit = 0; protected int marklimit;
/** /**
* This is the maximum size we have to allocate for the mark buffer. * This is the maximum size we have to allocate for the mark buffer.
...@@ -260,7 +261,7 @@ public class BufferedInputStream extends FilterInputStream ...@@ -260,7 +261,7 @@ public class BufferedInputStream extends FilterInputStream
*/ */
public synchronized int read(byte[] b, int off, int len) throws IOException public synchronized int read(byte[] b, int off, int len) throws IOException
{ {
if (off < 0 || len < 0 || off + len > b.length) if (off < 0 || len < 0 || b.length - off < len)
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
if (pos >= count && !refill()) if (pos >= count && !refill())
...@@ -286,13 +287,13 @@ public class BufferedInputStream extends FilterInputStream ...@@ -286,13 +287,13 @@ public class BufferedInputStream extends FilterInputStream
* passed when establishing the mark. * passed when establishing the mark.
* *
* @exception IOException If <code>mark()</code> was never called or more * @exception IOException If <code>mark()</code> was never called or more
* then <code>markLimit</code> bytes were read since the last * then <code>marklimit</code> bytes were read since the last
* call to <code>mark()</code> * call to <code>mark()</code>
*/ */
public synchronized void reset() throws IOException public synchronized void reset() throws IOException
{ {
if (markpos < 0) if (markpos == -1)
throw new IOException(); throw new IOException(buf == null ? "Stream closed." : "Invalid mark.");
pos = markpos; pos = markpos;
} }
...@@ -310,6 +311,9 @@ public class BufferedInputStream extends FilterInputStream ...@@ -310,6 +311,9 @@ public class BufferedInputStream extends FilterInputStream
*/ */
public synchronized long skip(long n) throws IOException public synchronized long skip(long n) throws IOException
{ {
if (buf == null)
throw new IOException("Stream closed.");
final long origN = n; final long origN = n;
while (n > 0L) while (n > 0L)
...@@ -332,14 +336,16 @@ public class BufferedInputStream extends FilterInputStream ...@@ -332,14 +336,16 @@ public class BufferedInputStream extends FilterInputStream
} }
/** /**
* Called to refill the buffer (when count is equal or greater the pos). * Called to refill the buffer (when count is equal to pos).
* Package local so BufferedReader can call it when needed.
* *
* @return <code>true</code> when <code>buf</code> can be (partly) refilled, * @return <code>true</code> when at least one additional byte was read
* <code>false</code> otherwise. * into <code>buf</code>, <code>false</code> otherwise (at EOF).
*/ */
boolean refill() throws IOException boolean refill() throws IOException
{ {
if (buf == null)
throw new IOException("Stream closed.");
if (markpos < 0) if (markpos < 0)
count = pos = 0; count = pos = 0;
else if (markpos > 0) else if (markpos > 0)
......
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