Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D9038C9FE for ; Thu, 7 Jun 2012 23:24:10 +0000 (UTC) Received: (qmail 45518 invoked by uid 500); 7 Jun 2012 23:24:10 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 45460 invoked by uid 500); 7 Jun 2012 23:24:10 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 45450 invoked by uid 99); 7 Jun 2012 23:24:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2012 23:24:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2012 23:24:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 08E152388860 for ; Thu, 7 Jun 2012 23:23:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1347829 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/input/Tailer.java test/java/org/apache/commons/io/input/TailerTest.java Date: Thu, 07 Jun 2012 23:23:48 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120607232349.08E152388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Thu Jun 7 23:23:48 2012 New Revision: 1347829 URL: http://svn.apache.org/viewvc?rev=1347829&view=rev Log: IO-334 - Tailer#readLines - incorrect CR handling Modified: commons/proper/io/trunk/src/changes/changes.xml commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java Modified: commons/proper/io/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1347829&r1=1347828&r2=1347829&view=diff ============================================================================== --- commons/proper/io/trunk/src/changes/changes.xml (original) +++ commons/proper/io/trunk/src/changes/changes.xml Thu Jun 7 23:23:48 2012 @@ -47,6 +47,9 @@ The type attribute can be add,u + + Tailer#readLines - incorrect CR handling. + FileUtils.toURLs throws NPE for null parameter. Documented the behaviour. Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java?rev=1347829&r1=1347828&r2=1347829&view=diff ============================================================================== --- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java (original) +++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java Thu Jun 7 23:23:48 2012 @@ -385,17 +385,23 @@ public class Tailer implements Runnable byte ch = inbuf[i]; switch (ch) { case '\n': + seenCR = false; // swallow CR before LF listener.handle(sb.toString()); - sb = new StringBuilder(); + sb.setLength(0); rePos = pos + i + 1; break; case '\r': + if (seenCR) { + sb.append('\r'); + } seenCR = true; break; default: if (seenCR) { - sb.append('\r'); - seenCR = false; + seenCR = false; // swallow final CR + listener.handle(sb.toString()); + sb.setLength(0); + rePos = pos + i + 1; } sb.append((char) ch); // add character, not its ascii value } Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java?rev=1347829&r1=1347828&r2=1347829&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java Thu Jun 7 23:23:48 2012 @@ -290,6 +290,35 @@ public class TailerTest extends FileBase assertEquals("fileRotated should be not be called", 0 , listener.rotated); } + public void testIO335() throws Exception { // test CR behaviour + // Create & start the Tailer + long delayMillis = 50; + final File file = new File(getTestDirectory(), "tailer-testio334.txt"); + createFile(file, 0); + final TestTailerListener listener = new TestTailerListener(); + tailer = new Tailer(file, listener, delayMillis, false); + final Thread thread = new Thread(tailer); + thread.start(); + + // Write some lines to the file + writeString(file, "CRLF\r\nLF\nCR\rCRCR\r\rtrail"); + // 1 2 3 4 + final long testDelayMillis = delayMillis * 10; + Thread.sleep(testDelayMillis); + List lines = listener.getLines(); + assertEquals("line count", 4, lines.size()); + assertEquals("line 1", "CRLF", lines.get(0)); + assertEquals("line 2", "LF", lines.get(1)); + assertEquals("line 3", "CR", lines.get(2)); + assertEquals("line 4", "CRCR\r", lines.get(3)); + + // Stop + tailer.stop(); + tailer=null; + thread.interrupt(); + Thread.sleep(testDelayMillis); + } + /** * Test {@link TailerListener} implementation. */