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;
+    }
+
 }


Reply via email to