This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

CharArrayReader, ByteArrayInputStream


Some minor corrections to problems that showed up by Kaffe's tests.

regards

  [ bryce ]


2001-02-19  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/io/CharArrayReader.java (CharArrayReader): Throw 
	IllegalArgumentException if constructor arguments are illegal.
	(ready): Return false if no more characters can be read.
	* java/io/ByteArrayInputStream.java (ByteArrayInputStream): Likewise.

Index: java/io/CharArrayReader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/CharArrayReader.java,v
retrieving revision 1.3.4.1
diff -u -r1.3.4.1 CharArrayReader.java
--- CharArrayReader.java	2001/02/17 01:06:44	1.3.4.1
+++ CharArrayReader.java	2001/02/19 05:27:05
@@ -41,17 +41,16 @@
   public CharArrayReader(char[] buffer, int offset, int length)
   {
     super();
+    if (offset < 0  || length < 0 || offset > buffer.length)
+      throw new IllegalArgumentException();
+    
     buf = buffer;
 
     count = offset + length;
     if (count > buf.length)
       count = buf.length;
-
+    
     pos = offset;
-    // TBD: What should we do if pos is neg. or > count?  E.g. throw exc. or:
-    // if (pos < 0 || pos > count)
-    //   pos = 0;
-
     markedPos = pos;
   }
 
@@ -116,12 +115,17 @@
     }
   }
 
+  /** Return true if more characters are available to be read. 
+    *
+    * @specnote The JDK 1.3 API docs are wrong here. This method will
+    *           return false if there are no more characters available.
+    */
   public boolean ready() throws IOException
   {
     if (buf == null)
       throw new IOException("Stream closed");
 
-    return true;
+    return (pos < count);
   }
 
   public void reset() throws IOException
Index: java/io/ByteArrayInputStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/ByteArrayInputStream.java,v
retrieving revision 1.4
diff -u -r1.4 ByteArrayInputStream.java
--- ByteArrayInputStream.java	2000/11/29 10:06:03	1.4
+++ ByteArrayInputStream.java	2001/02/19 05:27:05
@@ -40,6 +40,9 @@
 
   public ByteArrayInputStream(byte[] buffer, int offset, int length)
   {
+    if (offset < 0  || length < 0 || offset > buffer.length)
+      throw new IllegalArgumentException();
+
     buf = buffer;
 
     count = offset + length;
@@ -47,10 +50,6 @@
       count = buf.length;
 
     pos = offset;
-    // TBD: What should we do if pos is neg. or > count?  E.g. throw exc. or:
-    // if (pos < 0 || pos > count)
-    //   pos = 0;
-
     mark = pos;
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]