Patch: java.io bug fixes
Tom Tromey
tromey@cygnus.com
Tue Jun 27 14:27:00 GMT 2000
Here are a couple minor java.io bug fixes that I'm checking in.
The problem here is that super.read() can return -1, yielding an
incorrect result.
2000-06-27 Tom Tromey <tromey@cygnus.com>
* java/io/PushbackInputStream.java (read): If there are characters
in the buffer, don't also call super.read().
* java/io/PushbackReader.java (read): If there are characters in
the buffer, don't also call super.read().
Tom
Index: java/io/PushbackInputStream.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/PushbackInputStream.java,v
retrieving revision 1.3
diff -u -r1.3 PushbackInputStream.java
--- PushbackInputStream.java 2000/03/07 19:55:26 1.3
+++ PushbackInputStream.java 2000/06/27 21:25:33
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj.
@@ -70,12 +70,14 @@
throw new ArrayIndexOutOfBoundsException();
int numBytes = Math.min(buf.length - pos, len);
- for (int i = 0; i < numBytes; i++)
- b[off++] = buf[pos++];
+ if (numBytes > 0)
+ {
+ System.arraycopy (buf, pos, b, off, numBytes);
+ pos += numBytes;
+ return numBytes;
+ }
- // `off' was just incremented to include `numBytes', so we can
- // just pass ithere.
- return numBytes + super.read(b, off, len - numBytes);
+ return super.read(b, off, len);
}
public void unread(int b) throws IOException
Index: java/io/PushbackReader.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/PushbackReader.java,v
retrieving revision 1.3
diff -u -r1.3 PushbackReader.java
--- PushbackReader.java 2000/03/07 19:55:26 1.3
+++ PushbackReader.java 2000/06/27 21:25:33
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj.
@@ -79,10 +79,14 @@
throw new ArrayIndexOutOfBoundsException();
int numBytes = Math.min(buf.length - pos, len);
- for (int i = 0; i < numBytes; i++)
- b[off++] = buf[pos++];
+ if (numBytes > 0)
+ {
+ System.arraycopy (buf, pos, b, off, numBytes);
+ pos += numBytes;
+ return numBytes;
+ }
- return numBytes + super.read(b, off, len - numBytes);
+ return super.read(b, off, len);
}
}
More information about the Java-patches
mailing list