Commit 45d51d7e by Guilhem Lavaux Committed by Michael Koch

BufferedReader.java (BufferedReader): Throw IllegalArgumentException when size <= 0.

2003-12-26  Guilhem Lavaux  <guilhem@kaffe.org>
	    Mark Wielaard  <mark@klomp.org>

	* java/io/BufferedReader.java (BufferedReader):
	Throw IllegalArgumentException when size <= 0.
	(mark): Document and better exception message for negative
	readLimit IllegalArgumentException.
	(read(char[],int,int)): Throw IndexOutOfBoundsException
	if offset and count are not valid regarding buf.
	(skip): Throw IllegalArgumentException when count is negative.

Co-Authored-By: Mark Wielaard <mark@klomp.org>

From-SVN: r75041
parent 3364872d
2003-12-26 Guilhem Lavaux <guilhem@kaffe.org> 2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
Mark Wielaard <mark@klomp.org>
* java/io/BufferedReader.java (BufferedReader):
Throw IllegalArgumentException when size <= 0.
(mark): Document and better exception message for negative
readLimit IllegalArgumentException.
(read(char[],int,int)): Throw IndexOutOfBoundsException
if offset and count are not valid regarding buf.
(skip): Throw IllegalArgumentException when count is negative.
2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
* java/io/FileInputStream.java * java/io/FileInputStream.java
(FileInputStream(String)): Call FileInputStream(File). (FileInputStream(String)): Call FileInputStream(File).
......
...@@ -106,10 +106,14 @@ public class BufferedReader extends Reader ...@@ -106,10 +106,14 @@ public class BufferedReader extends Reader
* *
* @param in The subordinate stream to read from * @param in The subordinate stream to read from
* @param size The buffer size to use * @param size The buffer size to use
*
* @exception IllegalArgumentException if size &lt;&eq; 0
*/ */
public BufferedReader(Reader in, int size) public BufferedReader(Reader in, int size)
{ {
super(in.lock); super(in.lock);
if (size <= 0)
throw new IllegalArgumentException("Illegal buffer size: " + size);
this.in = in; this.in = in;
buffer = new char[size]; buffer = new char[size];
} }
...@@ -161,11 +165,12 @@ public class BufferedReader extends Reader ...@@ -161,11 +165,12 @@ public class BufferedReader extends Reader
* becomes invalid * becomes invalid
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception IllegalArgumentException if readLimit is negative.
*/ */
public void mark(int readLimit) throws IOException public void mark(int readLimit) throws IOException
{ {
if (readLimit < 0) if (readLimit < 0)
throw new IllegalArgumentException(); throw new IllegalArgumentException("Read-ahead limit is negative");
synchronized (lock) synchronized (lock)
{ {
...@@ -280,9 +285,14 @@ public class BufferedReader extends Reader ...@@ -280,9 +285,14 @@ public class BufferedReader extends Reader
* @return The actual number of chars read, or -1 if end of stream. * @return The actual number of chars read, or -1 if end of stream.
* *
* @exception IOException If an error occurs. * @exception IOException If an error occurs.
* @exception IndexOutOfBoundsException If offset and count are not
* valid regarding buf.
*/ */
public int read(char[] buf, int offset, int count) throws IOException public int read(char[] buf, int offset, int count) throws IOException
{ {
if (offset < 0 || offset + count > buf.length || count < 0)
throw new IndexOutOfBoundsException();
synchronized (lock) synchronized (lock)
{ {
checkStatus(); checkStatus();
...@@ -487,14 +497,17 @@ public class BufferedReader extends Reader ...@@ -487,14 +497,17 @@ public class BufferedReader extends Reader
* *
* @return The actual number of chars skipped. * @return The actual number of chars skipped.
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs.
* @exception IllegalArgumentException If count is negative.
*/ */
public long skip(long count) throws IOException public long skip(long count) throws IOException
{ {
synchronized (lock) synchronized (lock)
{ {
checkStatus(); checkStatus();
if (count <= 0) if (count < 0)
throw new IllegalArgumentException("skip value is negative");
if (count == 0)
return 0; return 0;
// Yet again, we need to handle the special case of a readLine // Yet again, we need to handle the special case of a readLine
// that has a '\r' at the end of the buffer. In this case, we need // that has a '\r' at the end of the buffer. In this case, we need
......
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