java.io.Inputs and java.io.Ouputs
Mark Thornton
mthornton at optrak.co.uk
Mon Nov 17 13:35:19 PST 2008
Rémi Forax wrote:
>>> - readAllLines should be lazy, i.e. returns an Iterable<String>,
>>> its iterator should close the stream when hasNext() return false.
>>> I think Python already do something like that.
>> I don't think this is feasible here. There is no guarantee that the
>> user will iterate to the end (due to an exception for example). Also,
>> there is no guarantee that the source will remain accessible. For
>> example, somebody might want to read all the lines from a text file
>> and delete the file immediately. Also, if the InputStream is to a
>> network resource (a http connection for example) then I/O would need
>> to be exposed by the iterator.
> I suppose we have to wait closures :)
You consider an interface like
interface LineFilter {
appendLine(CharSequence s);
}
and then readAllLines(LineFilter f);
BufferedWriter could implement the interface.
Mark Thornton
More information about the nio-dev
mailing list