summaryrefslogtreecommitdiffstats
path: root/libjava/java/io
diff options
context:
space:
mode:
authorbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2002-03-25 02:28:22 +0000
committerbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2002-03-25 02:28:22 +0000
commit2e3c045e62c2b71c7f65205ffa6c17c61e571ab2 (patch)
treec3e7066f8f9ad0c5621e3f1f8b8d25626ab67205 /libjava/java/io
parent194f956bb8f875759c57c282b5d052a26f83a6d5 (diff)
downloadppe42-gcc-2e3c045e62c2b71c7f65205ffa6c17c61e571ab2.tar.gz
ppe42-gcc-2e3c045e62c2b71c7f65205ffa6c17c61e571ab2.zip
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51296 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/io')
-rw-r--r--libjava/java/io/PushbackInputStream.java19
1 files changed, 12 insertions, 7 deletions
diff --git a/libjava/java/io/PushbackInputStream.java b/libjava/java/io/PushbackInputStream.java
index 7afd3d5e5cd..ebf0e38616a 100644
--- a/libjava/java/io/PushbackInputStream.java
+++ b/libjava/java/io/PushbackInputStream.java
@@ -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 class PushbackInputStream extends FilterInputStream
*/
public int available() throws IOException
{
- return pos + super.available();
+ return (buf.length - pos) + super.available();
}
/**
@@ -200,18 +200,23 @@ public class PushbackInputStream extends FilterInputStream
*/
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;
}
/**
OpenPOWER on IntegriCloud