diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-12-28 11:54:17 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-12-28 11:54:17 +0000 |
commit | 150e25c63c0ce260d6f307f16dcee9061ec9a1ef (patch) | |
tree | 41837312c288c51281dc7c93eade8553e241f38a /libjava | |
parent | 61f5be706027e91f1ea698c74f04466a89c2c4dd (diff) | |
download | ppe42-gcc-150e25c63c0ce260d6f307f16dcee9061ec9a1ef.tar.gz ppe42-gcc-150e25c63c0ce260d6f307f16dcee9061ec9a1ef.zip |
2003-12-28 Guilhem Lavaux <guilhem@kaffe.org>
* java/io/LineNumberReader.java
(mark): Improved error checking.
(read): Likewise.
(skip): Likewise. Skip is now really eating the specified number of
characters.
* java/io/CharArrayReader.java (read): It should throw
IndexOutOfBoundsException and not ArrayIndexOutOfBoundsException (see
mauve).
* java/io/BufferedReader.java (readLine): Make readLine() really block
until either EOF is reached or a true error happens.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75180 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 13 | ||||
-rw-r--r-- | libjava/java/io/BufferedReader.java | 15 | ||||
-rw-r--r-- | libjava/java/io/CharArrayReader.java | 2 | ||||
-rw-r--r-- | libjava/java/io/LineNumberReader.java | 20 |
4 files changed, 42 insertions, 8 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index a657e5a6b0e..493c3bb3407 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,16 @@ +2003-12-28 Guilhem Lavaux <guilhem@kaffe.org> + + * java/io/LineNumberReader.java + (mark): Improved error checking. + (read): Likewise. + (skip): Likewise. Skip is now really eating the specified number of + characters. + * java/io/CharArrayReader.java (read): It should throw + IndexOutOfBoundsException and not ArrayIndexOutOfBoundsException (see + mauve). + * java/io/BufferedReader.java (readLine): Make readLine() really block + until either EOF is reached or a true error happens. + 2003-12-27 Michael Koch <konqueror@gmx.de> * gnu/java/net/protocol/http/Connection.java diff --git a/libjava/java/io/BufferedReader.java b/libjava/java/io/BufferedReader.java index 73fb47c5d34..e29c8dd8844 100644 --- a/libjava/java/io/BufferedReader.java +++ b/libjava/java/io/BufferedReader.java @@ -460,12 +460,19 @@ public class BufferedReader extends Reader boolean eof = false; for (;;) { - int ch = read(); - if (ch < 0) + // readLine should block. So we must not return until a -1 is reached. + if (pos >= limit) { - eof = true; - break; + // here count == 0 isn't sufficient to give a failure. + int count = fill(); + if (count < 0) + { + eof = true; + break; + } + continue; } + int ch = buffer[pos++]; if (ch == '\n' || ch == '\r') { // Check here if a '\r' was the last char in the buffer; if so, diff --git a/libjava/java/io/CharArrayReader.java b/libjava/java/io/CharArrayReader.java index f379519b834..9d5382bef1e 100644 --- a/libjava/java/io/CharArrayReader.java +++ b/libjava/java/io/CharArrayReader.java @@ -228,7 +228,7 @@ public class CharArrayReader extends Reader /* Don't need to check pos value, arraycopy will check it. */ if (off < 0 || len < 0 || off + len > b.length) - throw new ArrayIndexOutOfBoundsException(); + throw new IndexOutOfBoundsException(); if (pos >= count) return -1; diff --git a/libjava/java/io/LineNumberReader.java b/libjava/java/io/LineNumberReader.java index 9c4796d402f..439a760fbf1 100644 --- a/libjava/java/io/LineNumberReader.java +++ b/libjava/java/io/LineNumberReader.java @@ -155,6 +155,9 @@ public class LineNumberReader extends BufferedReader */ 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 @@ public class LineNumberReader extends BufferedReader * @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 class LineNumberReader extends BufferedReader */ 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; |