From 2c11433f202147fd3bfd88f2b1b22e9e91c06d91 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Mon, 27 Sep 2004 09:27:28 +0000 Subject: [PATCH] 2004-09-27 Michael Koch * 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 --- libjava/ChangeLog | 12 ++++++++++ libjava/java/io/BufferedInputStream.java | 28 ++++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 2794b78266f..41ba9314b5f 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,15 @@ +2004-09-27 Michael Koch + + * 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 * prims.cc (unblock_signal): Annotate signum with __unused__ to diff --git a/libjava/java/io/BufferedInputStream.java b/libjava/java/io/BufferedInputStream.java index cd8e681ed1f..3faaa6591d4 100644 --- a/libjava/java/io/BufferedInputStream.java +++ b/libjava/java/io/BufferedInputStream.java @@ -61,6 +61,7 @@ package java.io; * * @author Aaron M. Renn (arenn@urbanophile.com) * @author Warren Levy + * @author Jeroen Frijters */ 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 * 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. * When pos == count, the buffer is empty. */ - protected int pos = 0; + protected int pos; /** * The value of pos when the mark() method was @@ -100,7 +101,7 @@ public class BufferedInputStream extends FilterInputStream * After this may bytes are read, the reset() method * 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. @@ -260,7 +261,7 @@ public class BufferedInputStream extends FilterInputStream */ 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(); if (pos >= count && !refill()) @@ -286,13 +287,13 @@ public class BufferedInputStream extends FilterInputStream * passed when establishing the mark. * * @exception IOException If mark() was never called or more - * then markLimit bytes were read since the last + * then marklimit bytes were read since the last * call to mark() */ public synchronized void reset() throws IOException { - if (markpos < 0) - throw new IOException(); + if (markpos == -1) + throw new IOException(buf == null ? "Stream closed." : "Invalid mark."); pos = markpos; } @@ -310,6 +311,9 @@ public class BufferedInputStream extends FilterInputStream */ public synchronized long skip(long n) throws IOException { + if (buf == null) + throw new IOException("Stream closed."); + final long origN = n; while (n > 0L) @@ -332,14 +336,16 @@ public class BufferedInputStream extends FilterInputStream } /** - * Called to refill the buffer (when count is equal or greater the pos). - * Package local so BufferedReader can call it when needed. + * Called to refill the buffer (when count is equal to pos). * - * @return true when buf can be (partly) refilled, - * false otherwise. + * @return true when at least one additional byte was read + * into buf, false otherwise (at EOF). */ boolean refill() throws IOException { + if (buf == null) + throw new IOException("Stream closed."); + if (markpos < 0) count = pos = 0; else if (markpos > 0) -- 2.30.2