commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaco...@apache.org
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 GMT
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 <code>c</code>
-  * @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));
   }



Mime
View raw message