This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[Patch] java.io.BufferedInputStream.skip(long)...
- From: David Daney <ddaney at avtrex dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Tue, 16 Nov 2004 14:14:27 -0800
- Subject: [Patch] java.io.BufferedInputStream.skip(long)...
InputStream.skip(long) should (i.e. is required to) return the number of
bytes skipped.
BufferedInputStream was returning -1 on EOF in violation of the specification.
This patch corrects the problem by returning 0 (zero) when skip() is called
at EOF.
Tested on i686-pc-linux-gnu with make check in libjava with no regressions.
OK to commit?
David Daney
2004-11-16 David Daney <ddaney@avtrex.com>
* java/io/BufferedInputStream.java (skip): Return zero on EOF.
* testsuite/libjava.lang/BufferedInputStream_1.java,
testsuite/libjava.lang/BufferedInputStream_1.out: New test.
Index: java/io/BufferedInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/BufferedInputStream.java,v
retrieving revision 1.9
diff -c -p -r1.9 BufferedInputStream.java
*** java/io/BufferedInputStream.java 18 Oct 2004 13:40:04 -0000 1.9
--- java/io/BufferedInputStream.java 16 Nov 2004 21:56:03 -0000
*************** public class BufferedInputStream extends
*** 321,327 ****
if (n < origN)
break;
else
! return -1; // No bytes were read before EOF.
int numread = (int) Math.min((long) (count - pos), n);
pos += numread;
--- 321,327 ----
if (n < origN)
break;
else
! return 0; // No bytes were read before EOF.
int numread = (int) Math.min((long) (count - pos), n);
pos += numread;
Index: testsuite/libjava.lang/BufferedInputStream_1.java
===================================================================
RCS file: testsuite/libjava.lang/BufferedInputStream_1.java
diff -N testsuite/libjava.lang/BufferedInputStream_1.java
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/libjava.lang/BufferedInputStream_1.java 16 Nov 2004 21:56:03 -0000
***************
*** 0 ****
--- 1,37 ----
+ // Verify that skip does not return a negitive number on EOF.
+ //
+
+ import java.io.BufferedInputStream;
+ import java.io.ByteArrayInputStream;
+
+ public class BufferedInputStream_1
+ {
+ public static void main(String[] args)
+ {
+ try
+ {
+ byte[] ba = new byte[]{0x44, 0x55};
+ ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+ BufferedInputStream bis = new BufferedInputStream(bais);
+ long s = bis.skip(2);
+ if (s != 2)
+ {
+ System.out.println("bad 1");
+ System.exit(1);
+ }
+ s = bis.skip(2);
+ if (s < 0)
+ {
+ System.out.println("bad 2");
+ System.exit(1);
+ }
+ System.out.println("ok");
+ System.exit(0);
+ }
+ catch (Exception ex)
+ {
+ System.out.println(ex.toString());
+ }
+ System.exit(1);
+ }
+ }
Index: testsuite/libjava.lang/BufferedInputStream_1.out
===================================================================
RCS file: testsuite/libjava.lang/BufferedInputStream_1.out
diff -N testsuite/libjava.lang/BufferedInputStream_1.out
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/libjava.lang/BufferedInputStream_1.out 16 Nov 2004 21:56:03 -0000
***************
*** 0 ****
--- 1 ----
+ ok