harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r552898 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/LineNumberReader.java test/api/common/tests/api/java/io/LineNumberReaderTest.java
Date Tue, 03 Jul 2007 16:25:01 GMT
Author: tonywu
Date: Tue Jul  3 09:24:57 2007
New Revision: 552898

URL: http://svn.apache.org/viewvc?view=rev&rev=552898
Log:
Fix Harmony-4294 ([classlib][io] LineNumberReader treats \r\n as two lines)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberReader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/LineNumberReaderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberReader.java?view=diff&rev=552898&r1=552897&r2=552898
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberReader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/LineNumberReader.java
Tue Jul  3 09:24:57 2007
@@ -196,18 +196,8 @@
     @Override
     public String readLine() throws IOException {
         synchronized (lock) {
-            /* Typical Line Length */
-            StringBuilder result = new StringBuilder(80);
-            while (true) {
-                int character = read();
-                if (character == -1) {
-                    return result.length() != 0 ? result.toString() : null;
-                }
-                if (character == '\n') {
-                    return result.toString();
-                }
-                result.append((char) character);
-            }
+            lineNumber++;
+            return super.readLine();
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/LineNumberReaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/LineNumberReaderTest.java?view=diff&rev=552898&r1=552897&r2=552898
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/LineNumberReaderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/LineNumberReaderTest.java
Tue Jul  3 09:24:57 2007
@@ -17,7 +17,9 @@
 
 package tests.api.java.io;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.LineNumberReader;
 import java.io.StringReader;
 
@@ -125,9 +127,10 @@
 	}
 
 	/**
+	 * @throws IOException 
 	 * @tests java.io.LineNumberReader#readLine()
 	 */
-	public void test_readLine() {
+	public void test_readLine() throws IOException {
 		// Test for method java.lang.String java.io.LineNumberReader.readLine()
 		lnr = new LineNumberReader(new StringReader(text));
 		assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
@@ -141,6 +144,17 @@
 		assertEquals("Returned incorrect string", "1", line);
 		assertTrue("Returned incorrect line number :" + lnr.getLineNumber(),
 				lnr.getLineNumber() == 2);
+        
+        //Regression for HARMONY-4294
+        byte[] buffer = new byte[] { '\r', '\n' };
+        LineNumberReader reader = new LineNumberReader(new InputStreamReader(
+                new ByteArrayInputStream(buffer)));
+        assertEquals('\n',reader.read());
+        assertEquals(-1,reader.read());
+        reader = new LineNumberReader(new InputStreamReader(
+                new ByteArrayInputStream(buffer)));
+        assertNotNull(reader.readLine());
+        assertNull(reader.readLine());
 	}
 
 	/**



Mime
View raw message