[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: java.io.LineNumberReader
From: |
Guilhem Lavaux |
Subject: |
FYI: java.io.LineNumberReader |
Date: |
Sun, 28 Dec 2003 11:05:59 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007 |
Hi,
Here is a patch to improve error reporting in java.io.LineNumberReader.
skip() also eats the right number of character now (maybe it can be
improved).
Guilhem.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.1724
diff -u -r1.1724 ChangeLog
--- ChangeLog 27 Dec 2003 16:29:52 -0000 1.1724
+++ ChangeLog 28 Dec 2003 10:04:34 -0000
@@ -1,3 +1,11 @@
+2003-12-28 Guilhem Lavaux <address@hidden>
+
+ * java/io/LineNumberReader.java
+ (mark): Improved error checking.
+ (read): Likewise.
+ (skip): Likewise. Skip is now really eating the specified number of
+ characters.
+
2003-12-27 Guilhem Lavaux <address@hidden>
* gnu/java/net/protocol/http/Connection.java
Index: java/io/LineNumberReader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/LineNumberReader.java,v
retrieving revision 1.11
diff -u -r1.11 LineNumberReader.java
--- java/io/LineNumberReader.java 31 Aug 2003 19:45:06 -0000 1.11
+++ java/io/LineNumberReader.java 28 Dec 2003 10:04:34 -0000
@@ -155,6 +155,9 @@
*/
public void mark(int readLimit) throws IOException
{
+ if (readLimit < 0)
+ throw new IllegalArgumentException("Read-ahead limit is negative");
+
synchronized (lock)
{
// This is basically the same as BufferedReader.mark.
@@ -265,9 +268,17 @@
* @return The actual number of chars read, or -1 if end of stream
*
* @exception IOException If an error occurs.
+ * @exception NullPointerException If buf is null (in any case).
+ * @exception IndexOutOfBoundsException If buffer parameters (offset and
+ * count) lies outside of the buffer capacity.
*/
public int read(char[] buf, int offset, int count) throws IOException
{
+ if (buf == null)
+ throw new NullPointerException();
+ if (offset + count > buf.length || offset < 0)
+ throw new IndexOutOfBoundsException();
+
if (count <= 0)
{
if (count < 0)
@@ -376,14 +387,17 @@
*/
public long skip (long count) throws IOException
{
- if (count <= 0)
+ if (count < 0)
+ throw new IllegalArgumentException("skip() value is negative");
+ if (count == 0)
return 0;
int skipped;
-
+ char[] buf = new char[1];
+
for (skipped = 0; skipped < count; skipped++)
{
- int ch = read();
+ int ch = read(buf, 0, 1);
if (ch < 0)
break;
- FYI: java.io.LineNumberReader,
Guilhem Lavaux <=