Commit be454565 by Bryce McKinlay Committed by Bryce McKinlay

CharArrayReader.java (CharArrayReader): Throw IllegalArgumentException if…

CharArrayReader.java (CharArrayReader): Throw IllegalArgumentException if constructor arguments are illegal.

	* 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.

From-SVN: r39876
parent 612164eb
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
property is not set. Don't call decode with null argument. property is not set. Don't call decode with null argument.
* java/lang/Long.java (getLong): Likewise. * java/lang/Long.java (getLong): Likewise.
* 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.
2001-02-17 Mark Wielaard <mark@klomp.org> 2001-02-17 Mark Wielaard <mark@klomp.org>
* java/util/TimerTask.java: New version from Classpath. * java/util/TimerTask.java: New version from Classpath.
......
...@@ -40,6 +40,9 @@ public class ByteArrayInputStream extends InputStream ...@@ -40,6 +40,9 @@ public class ByteArrayInputStream extends InputStream
public ByteArrayInputStream(byte[] buffer, int offset, int length) public ByteArrayInputStream(byte[] buffer, int offset, int length)
{ {
if (offset < 0 || length < 0 || offset > buffer.length)
throw new IllegalArgumentException();
buf = buffer; buf = buffer;
count = offset + length; count = offset + length;
...@@ -47,10 +50,6 @@ public class ByteArrayInputStream extends InputStream ...@@ -47,10 +50,6 @@ public class ByteArrayInputStream extends InputStream
count = buf.length; count = buf.length;
pos = offset; 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; mark = pos;
} }
......
...@@ -41,17 +41,16 @@ public class CharArrayReader extends Reader ...@@ -41,17 +41,16 @@ public class CharArrayReader extends Reader
public CharArrayReader(char[] buffer, int offset, int length) public CharArrayReader(char[] buffer, int offset, int length)
{ {
super(); super();
if (offset < 0 || length < 0 || offset > buffer.length)
throw new IllegalArgumentException();
buf = buffer; buf = buffer;
count = offset + length; count = offset + length;
if (count > buf.length) if (count > buf.length)
count = buf.length; count = buf.length;
pos = offset; 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; markedPos = pos;
} }
...@@ -116,12 +115,17 @@ public class CharArrayReader extends Reader ...@@ -116,12 +115,17 @@ public class CharArrayReader extends Reader
} }
} }
/** 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 public boolean ready() throws IOException
{ {
if (buf == null) if (buf == null)
throw new IOException("Stream closed"); throw new IOException("Stream closed");
return true; return (pos < count);
} }
public void reset() throws IOException public void reset() throws IOException
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment