You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Niall Pemberton <ni...@gmail.com> on 2010/03/07 12:53:32 UTC

Re: svn commit: r919627 - /commons/proper/io/trunk/src/java/org/apache/commons/io/LineIterator.java

I'm still -1 to this - see comments in JIRA ticket

Niall

On Fri, Mar 5, 2010 at 9:31 PM,  <se...@apache.org> wrote:
> 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;
> +    }
> +
>  }
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org