commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Collins (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (IO-181) LineIterator should implement Iterable
Date Wed, 19 Aug 2009 05:33:15 GMT

    [ https://issues.apache.org/jira/browse/IO-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12744890#action_12744890
] 

Robert Collins edited comment on IO-181 at 8/18/09 10:31 PM:
-------------------------------------------------------------

Henri only noted that there is a Iterable->Iterator relationship. It's a fairly common
idiom in python to have single-pass Iterables (like files) allow iteration on this.

You can even separate out the Iterator code from the Iterable in those situations if needed.


I think it would be lovely if this was reopened (I'd be happy to write the patch) - contrast:
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
 try {
    for (String line : it) {
     /// do something with line
   }
 } finally {
   LineIterator.closeQuietly(iterator);
 }

for the sample use of LineIterator.

Its only less safe if someone abuses the contract - and they can do that without the convenience
method:

for (String line : (Iterable<String>)FileUtils.lineIterator(file, "UTF-8") {
     /// do something with line
   }



      was (Author: robertc):
    Henri only noted that there is a Iterable->Iterator relationship. It's a fairly common
idiom in python to have single-pass Iterables (like files) allow iteration on this.

You can even separate out the Iterator code from the Iterable in those situations if needed.


I think it would be lovely if this was reopened (I'd be happy to write the patch) - contrast:
try {
    
  
> LineIterator should implement Iterable 
> ---------------------------------------
>
>                 Key: IO-181
>                 URL: https://issues.apache.org/jira/browse/IO-181
>             Project: Commons IO
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Michael Ernst
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> org.apache.commons.io.LineIterator does not implement Iterable.  This makes
> it impossible to use in certain stylized ways, such as in a new-style for
> statement.  Such use is not always desirable (it might temporarily leak a
> file descriptor, until the finalizer is called), but should be possible in
> situations where it is known to be acceptable.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message