From c75b06ddc1765ebd01a90fad1cdf28f173bedf00 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Wed, 31 Aug 2011 20:46:15 -0600 Subject: [PATCH 1/3] Added support for non POSIX line endings. Will now accept: \r and \r\n as line endings (per Sun's JavaDoc) --- classpath/java/io/BufferedReader.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classpath/java/io/BufferedReader.java b/classpath/java/io/BufferedReader.java index 3db923c5e9..7b8e940681 100644 --- a/classpath/java/io/BufferedReader.java +++ b/classpath/java/io/BufferedReader.java @@ -42,9 +42,12 @@ public class BufferedReader extends Reader { } for (int i = position; i < limit; ++i) { - if (buffer[i] == '\n') { + if (buffer[i] == '\n' || buffer[i] == '\r') { sb.append(buffer, position, i - position); position = i + 1; + if(buffer[i+1] != null && buffer[i+1] == '\n') { + position = i + 1; + } return sb.toString(); } } From 97e03b9f286a8f59b7cfaff257ec6838a8eb7f05 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Thu, 1 Sep 2011 09:11:39 -0600 Subject: [PATCH 2/3] Fixed possible ArrayIndexOutOfBounds exception --- classpath/java/io/BufferedReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classpath/java/io/BufferedReader.java b/classpath/java/io/BufferedReader.java index 7b8e940681..9c77a3246a 100644 --- a/classpath/java/io/BufferedReader.java +++ b/classpath/java/io/BufferedReader.java @@ -45,7 +45,7 @@ public class BufferedReader extends Reader { if (buffer[i] == '\n' || buffer[i] == '\r') { sb.append(buffer, position, i - position); position = i + 1; - if(buffer[i+1] != null && buffer[i+1] == '\n') { + if(i+1 < limit && buffer[i+1] == '\n') { position = i + 1; } return sb.toString(); From fb3a23f02db789a8c49a2b7de149d685a77a22c0 Mon Sep 17 00:00:00 2001 From: Seth Goings Date: Thu, 1 Sep 2011 09:31:08 -0600 Subject: [PATCH 3/3] Fixed behavior of readLine accepting *\n\n as a line, not two --- classpath/java/io/BufferedReader.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/classpath/java/io/BufferedReader.java b/classpath/java/io/BufferedReader.java index 9c77a3246a..236a086b80 100644 --- a/classpath/java/io/BufferedReader.java +++ b/classpath/java/io/BufferedReader.java @@ -42,13 +42,18 @@ public class BufferedReader extends Reader { } for (int i = position; i < limit; ++i) { - if (buffer[i] == '\n' || buffer[i] == '\r') { + if(buffer[i] == '\r') { sb.append(buffer, position, i - position); position = i + 1; if(i+1 < limit && buffer[i+1] == '\n') { position = i + 1; + return sb.toString(); } return sb.toString(); + } else if (buffer[i] == '\n') { + sb.append(buffer, position, i - position); + position = i + 1; + return sb.toString(); } } sb.append(buffer, position, limit-position);