This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
CharArrayReader, ByteArrayInputStream
- To: java-patches at gcc dot gnu dot org
- Subject: CharArrayReader, ByteArrayInputStream
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Mon, 19 Feb 2001 18:40:08 +1300
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;
}