This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
PushbackInputStream fix
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- To: java-patches at gcc dot gnu dot org
- Date: Mon, 25 Mar 2002 14:29:06 +1200
- Subject: PushbackInputStream fix
This is a refined version of a patch to PushbackInputStream from Intel.
Previously available() would return incorrect values, and read() would
only return bytes in the pushback buffer if there were any.
Bryce.
2002-03-24 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
Based on patch from Intel's ORP team:
* java/io/PushbackInputStream.java (available): Calculate correct
number of bytes in buffer.
(read): Remove redundant bound check. Return bytes from both the
buffer and the stream.
Index: java/io/PushbackInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/PushbackInputStream.java,v
retrieving revision 1.6
diff -u -r1.6 PushbackInputStream.java
--- PushbackInputStream.java 2002/01/22 22:40:14 1.6
+++ PushbackInputStream.java 2002/03/25 02:26:11
@@ -1,5 +1,5 @@
/* PushbackInputStream.java -- An input stream that can unread bytes
- Copyright (C) 1998, 1999, 2001, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -116,7 +116,7 @@
*/
public int available() throws IOException
{
- return pos + super.available();
+ return (buf.length - pos) + super.available();
}
/**
@@ -200,18 +200,23 @@
*/
public synchronized int read(byte[] b, int off, int len) throws IOException
{
- if (off < 0 || len < 0 || off + len > b.length)
- throw new ArrayIndexOutOfBoundsException();
-
int numBytes = Math.min(buf.length - pos, len);
if (numBytes > 0)
{
System.arraycopy (buf, pos, b, off, numBytes);
pos += numBytes;
- return numBytes;
+ len -= numBytes;
+ off += numBytes;
}
- return super.read(b, off, len);
+ if (len > 0)
+ {
+ len = super.read(b, off, len);
+ if (len == -1) // EOF
+ return numBytes > 0 ? numBytes : -1;
+ numBytes += len;
+ }
+ return numBytes;
}
/**