[kaffe] Problem with BufferedInputStream [patch]
Mark Wielaard
mark@klomp.org
Thu Jun 5 09:43:01 2003
--=-KtZAe4pm+YWG7XkMqAJY
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Hi,
On Thu, 2003-06-05 at 17:54, Mark Wielaard wrote:
> On Thu, 2003-06-05 at 15:48, Helmer Krämer wrote:
> > So I would not completely remove the loop, but rather replace it with
> > something like "do {} while (len>0 && available()>0)"; dunno whether
> > that's really more correct, though...
> >
> > What do you think?
>
> Seems that is more correct. But since available() isn't that reliable I
> wouldn't implement it that way since it might make the method block much
> more then needed. See for example the java.util.ZipInputStream
> available() method definition (which says to almost always returns 1!).
>
> Also note that the javadoc say:
>
> Subclasses of this class are encouraged, but not required, to
> attempt to read as many bytes as possible in the same fashion.
>
> So users cannot rely on this behaviour anyway.
But I did try it out and the attached patch does what you suggest. Makes
the simple ReadLineTest and Snark work correctly and doesn't introduce
Mauve or make check regressions.
Cheers,
Mark
--=-KtZAe4pm+YWG7XkMqAJY
Content-Disposition: inline; filename=BufferedInputStream.patch2
Content-Type: text/x-patch; name=BufferedInputStream.patch2; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Index: libraries/javalib/java/io/BufferedInputStream.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/io/BufferedInputStream.java,v
retrieving revision 1.10
diff -u -r1.10 BufferedInputStream.java
--- libraries/javalib/java/io/BufferedInputStream.java 4 Apr 2003 06:11:41 -0000 1.10
+++ libraries/javalib/java/io/BufferedInputStream.java 5 Jun 2003 16:41:50 -0000
@@ -103,8 +103,8 @@
}
int total = 0;
- while (len > 0) {
+ do {
// If buffer fully consumed, invalidate mark & reset buffer
if (pos == buf.length) {
pos = count = 0;
@@ -138,7 +138,8 @@
pos += nread;
off += nread;
len -= nread;
- }
+ } while (len > 0 && available() > 0);
+
return total;
}
--=-KtZAe4pm+YWG7XkMqAJY--