commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r919627 - /commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java
Date Fri, 05 Mar 2010 21:31:19 GMT
Author: sebb
Date: Fri Mar  5 21:31:18 2010
New Revision: 919627

URL: http://svn.apache.org/viewvc?rev=919627&view=rev
Log:
IO-181 LineIterator should implement Iterable

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java?rev=919627&r1=919626&r2=919627&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java Fri Mar  5 21:31:18
2010
@@ -37,20 +37,19 @@
  * try {
  *   while (it.hasNext()) {
  *     String line = it.nextLine();
- *     /// do something with line
+ *     // do something with line
  *   }
  * } finally {
- *   LineIterator.closeQuietly(it);
+ *   it.close();
  * }
  * </pre>
- *
  * @author Niall Pemberton
  * @author Stephen Colebourne
  * @author Sandy McArthur
  * @version $Id$
  * @since Commons IO 1.2
  */
-public class LineIterator implements Iterator<String> {
+public class LineIterator implements Iterator<String>, Iterable<String> {
 
     /** The reader that is being read. */
     private final BufferedReader bufferedReader;
@@ -178,4 +177,26 @@
         }
     }
 
+    /**
+     * Returns the current instance.
+     * Shares the Reader with the other methods.
+     * <p> 
+     * Sample usage:
+     * </p>
+     * <pre>
+     * LineIterator it = FileUtils.lineIterator(file, "UTF-8");
+     * try {
+     *     for (String line : it) {
+     *         // do something with line
+     *     }
+     * } finally {
+     *     it.close();
+     * }
+     * </pre>
+     * 
+     */
+    public Iterator<String> iterator() {
+        return this;
+    }
+
 }



Mime
View raw message