Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 54869 invoked from network); 1 Feb 2011 08:19:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Feb 2011 08:19:25 -0000 Received: (qmail 44809 invoked by uid 500); 1 Feb 2011 08:19:25 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 44456 invoked by uid 500); 1 Feb 2011 08:19:22 -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 44448 invoked by uid 99); 1 Feb 2011 08:19:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Feb 2011 08:19:21 +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; Tue, 01 Feb 2011 08:19:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C257623889EA; Tue, 1 Feb 2011 08:18:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1065948 - in /commons/sandbox/csv/trunk/src: java/org/apache/commons/csv/ExtendedBufferedReader.java test/org/apache/commons/csv/ExtendedBufferedReaderTest.java Date: Tue, 01 Feb 2011 08:18:59 -0000 To: commits@commons.apache.org From: jacopoc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110201081859.C257623889EA@eris.apache.org> Author: jacopoc Date: Tue Feb 1 08:18:59 2011 New Revision: 1065948 URL: http://svn.apache.org/viewvc?rev=1065948&view=rev Log: Applied patch contributed by Henri Yandell in SANDBOX-219: "ExtendedBufferedReader does too much" Modified: commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/ExtendedBufferedReader.java commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/ExtendedBufferedReaderTest.java Modified: commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/ExtendedBufferedReader.java URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/ExtendedBufferedReader.java?rev=1065948&r1=1065947&r2=1065948&view=diff ============================================================================== --- commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/ExtendedBufferedReader.java (original) +++ commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/ExtendedBufferedReader.java Tue Feb 1 08:18:59 2011 @@ -29,9 +29,6 @@ import java.io.Reader; * In particular the reader supports a look-ahead option, * which allows you to see the next char returned by * next(). - * Furthermore the skip-method supports skipping until - * (but excluding) a given char. Similar functionality - * is supported by the reader as well. * */ class ExtendedBufferedReader extends BufferedReader { @@ -151,29 +148,6 @@ class ExtendedBufferedReader extends Buf } /** - * Reads all characters up to (but not including) the given character. - * - * @param c the character to read up to - * @return the string up to the character c - * @throws IOException - */ - public String readUntil(char c) throws IOException { - if (lookaheadChar == UNDEFINED) { - lookaheadChar = super.read(); - } - line.clear(); // reuse - while (lookaheadChar != c && lookaheadChar != END_OF_STREAM) { - line.append((char) lookaheadChar); - if (lookaheadChar == '\n') { - lineCounter++; - } - lastChar = lookaheadChar; - lookaheadChar = super.read(); - } - return line.toString(); - } - - /** * @return A String containing the contents of the line, not * including any line-termination characters, or null * if the end of the stream has been reached @@ -217,60 +191,10 @@ class ExtendedBufferedReader extends Buf } /** - * Skips char in the stream - * - * ATTENTION: invalidates the line-counter !!!!! - * - * @return nof skiped chars + * Unsupported */ public long skip(long n) throws IllegalArgumentException, IOException { - - if (lookaheadChar == UNDEFINED) { - lookaheadChar = super.read(); - } - - // illegal argument - if (n < 0) { - throw new IllegalArgumentException("negative argument not supported"); - } - - // no skipping - if (n == 0 || lookaheadChar == END_OF_STREAM) { - return 0; - } - - // skip and reread the lookahead-char - long skiped = 0; - if (n > 1) { - skiped = super.skip(n - 1); - } - lookaheadChar = super.read(); - // fixme uh: we should check the skiped sequence for line-terminations... - lineCounter = Integer.MIN_VALUE; - return skiped + 1; - } - - /** - * Skips all chars in the input until (but excluding) the given char - * - * @param c - * @return - * @throws IllegalArgumentException - * @throws IOException - */ - public long skipUntil(char c) throws IllegalArgumentException, IOException { - if (lookaheadChar == UNDEFINED) { - lookaheadChar = super.read(); - } - long counter = 0; - while (lookaheadChar != c && lookaheadChar != END_OF_STREAM) { - if (lookaheadChar == '\n') { - lineCounter++; - } - lookaheadChar = super.read(); - counter++; - } - return counter; + throw new UnsupportedOperationException("CSV has no reason to implement this"); } /** @@ -291,7 +215,6 @@ class ExtendedBufferedReader extends Buf /** * Returns the nof line read - * ATTENTION: the skip-method does invalidate the line-number counter * * @return the current-line-number (or -1) */ @@ -302,11 +225,12 @@ class ExtendedBufferedReader extends Buf return -1; } } + + /** + * Unsupported + */ public boolean markSupported() { - /* note uh: marking is not supported, cause we cannot - * see into the future... - */ - return false; + throw new UnsupportedOperationException("CSV has no reason to implement this"); } } Modified: commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/ExtendedBufferedReaderTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/ExtendedBufferedReaderTest.java?rev=1065948&r1=1065947&r2=1065948&view=diff ============================================================================== --- commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/ExtendedBufferedReaderTest.java (original) +++ commons/sandbox/csv/trunk/src/test/org/apache/commons/csv/ExtendedBufferedReaderTest.java Tue Feb 1 08:18:59 2011 @@ -115,10 +115,6 @@ public class ExtendedBufferedReaderTest } - public void testMarkSupported() { - assertFalse(getEBR("foo").markSupported()); - } - public void testReadLine() throws Exception { ExtendedBufferedReader br = getEBR(""); assertTrue(br.readLine() == null); @@ -161,61 +157,6 @@ public class ExtendedBufferedReaderTest assertTrue(br.readLine() == null); } - public void testSkip0() throws Exception { - - ExtendedBufferedReader br = getEBR(""); - assertEquals(0, br.skip(0)); - assertEquals(0, br.skip(1)); - - br = getEBR(""); - assertEquals(0, br.skip(1)); - - br = getEBR("abcdefg"); - assertEquals(0, br.skip(0)); - assertEquals('a', br.lookAhead()); - assertEquals(0, br.skip(0)); - assertEquals('a', br.lookAhead()); - assertEquals(1, br.skip(1)); - assertEquals('b', br.lookAhead()); - assertEquals('b', br.read()); - assertEquals(3, br.skip(3)); - assertEquals('f', br.lookAhead()); - assertEquals(2, br.skip(5)); - assertTrue(br.readLine() == null); - - br = getEBR("12345"); - assertEquals(5, br.skip(5)); - assertTrue (br.lookAhead() == ExtendedBufferedReader.END_OF_STREAM); - } - - public void testSkipUntil() throws Exception { - ExtendedBufferedReader br = getEBR(""); - assertEquals(0, br.skipUntil(';')); - br = getEBR("ABCDEF,GHL,,MN"); - assertEquals(6, br.skipUntil(',')); - assertEquals(0, br.skipUntil(',')); - br.skip(1); - assertEquals(3, br.skipUntil(',')); - br.skip(1); - assertEquals(0, br.skipUntil(',')); - br.skip(1); - assertEquals(2, br.skipUntil(',')); - } - - public void testReadUntil() throws Exception { - ExtendedBufferedReader br = getEBR(""); - assertTrue(br.readUntil(';').equals("")); - br = getEBR("ABCDEF;GHL;;MN"); - assertTrue(br.readUntil(';').equals("ABCDEF")); - assertTrue(br.readUntil(';').length() == 0); - br.skip(1); - assertTrue(br.readUntil(';').equals("GHL")); - br.skip(1); - assertTrue(br.readUntil(';').equals("")); - br.skip(1); - assertTrue(br.readUntil(',').equals("MN")); - } - private ExtendedBufferedReader getEBR(String s) { return new ExtendedBufferedReader(new StringReader(s)); }