commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 38083] - [io][PATCH] Iterate over the lines in a file and the files in a directory
Date Thu, 05 Jan 2006 23:12:28 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38083>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38083





------- Additional Comments From sjr@jdns.org  2006-01-06 00:12 -------
(In reply to comment #8)
> (In reply to comment #7)
> > I think it's better if you declare a return type of LineIterator. This way, no
> > casts are necessary. 
> 
> I'm neutral on that, but if thats whats required I'm happy to attach a new 
> version on that basis. Probably would be better if its an IOIterator, rather 
> than LineIterator though? I wasn't sure whether the having IOIterator that 
> extends Iterator to add a close() method or a separate interface with just the 
> close() was desired. Guess if the consensus is with you then better to extend 
> Iterator, otherwise it would have to return the implementation rather than the 
> type.

I think the IOIterator is a good idea. There is an interface "Closeable" Java
1.5 which is used for the same purpose.

>  IOIterator i = FileUtils.lineIterator( blah );

Sorry to be pedantic, but ...

Why declare i as an IOIterator when you can declare it as a LineIterator? I want
to iterate over Lines, not over IOs... But, anyway, the point is that if you
return LineIterator, you give the user the choice. We don't gain anything by
returning a superinterface in this case.

> 
> The other thing I wondered was maybe its better to have a new RuntimeException 
> that includes the "cause" (I assume io is JDK 1.3 dependant, and not 1.4) 
> rather than trapping IOException and re-throwing IllegalStateException with 
> just the message.

I don't think hasNext() should throw any exceptions. If you cannot read the file
anymore, then there are no more elements. People using the Iterator interface
will not expect hasNext() to throw an exception. Just close the reader as you
have done.

Also, next() should throw a NoSuchElementException, rather than 
IllegalStateException, according to the Iterator javadoc.

> Niall

Regards,
James

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


Mime
View raw message