Commit 8cf29a47 by Bryce McKinlay Committed by Bryce McKinlay

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.

From-SVN: r51296
parent acf9549e
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
* java/io/FileInputStream.java (skip): Call fd.getFilePointer() and * java/io/FileInputStream.java (skip): Call fd.getFilePointer() and
calculate correct number of bytes skipped. calculate correct number of bytes skipped.
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.
2002-03-24 Tom Tromey <tromey@redhat.com> 2002-03-24 Tom Tromey <tromey@redhat.com>
......
/* PushbackInputStream.java -- An input stream that can unread bytes /* 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. This file is part of GNU Classpath.
...@@ -116,7 +116,7 @@ public class PushbackInputStream extends FilterInputStream ...@@ -116,7 +116,7 @@ public class PushbackInputStream extends FilterInputStream
*/ */
public int available() throws IOException public int available() throws IOException
{ {
return pos + super.available(); return (buf.length - pos) + super.available();
} }
/** /**
...@@ -200,18 +200,23 @@ public class PushbackInputStream extends FilterInputStream ...@@ -200,18 +200,23 @@ public class PushbackInputStream 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)
throw new ArrayIndexOutOfBoundsException();
int numBytes = Math.min(buf.length - pos, len); int numBytes = Math.min(buf.length - pos, len);
if (numBytes > 0) if (numBytes > 0)
{ {
System.arraycopy (buf, pos, b, off, numBytes); System.arraycopy (buf, pos, b, off, numBytes);
pos += 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;
} }
/** /**
......
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