I/O Iterators for Java

(Back in 2003 I ran a moderately popular tech blog on the Radio UserLand platform. This is an archived version of a post from that blog. You can view an index of all the archived posts.)

Tuesday, 15 April 2003

While fleshing out the remaining parts of the primitives package in Commons Collections, a simple but potentially powerful feature became apparent. Using the byte-based primitive collections, it's not only easy but also efficient to bring together the I/O and Collections APIs via ByteIterator/InputStream adapters.

This allows one to treat any InputStream as a ByteIterator (and hence as an Iterator over Bytes) without resorting to a byte array buffer. This means that Iterator-based APIs like the functor algorithms can be applied to I/O streams. Similarly, this allows one to treat any ByteCollection (or Collection of Bytes) as a source for InputStreams. This means that stream-based APIs can be applied to ByteCollections and Collections of Bytes.

This brings Java one small step closer to the conceptual uniformity and resulting combinatorial expressiveness enjoyed by languages like Lisp. This is reason enough in my mind to extend the primitive collections to Char/char and to Reader-adapters as well.

(Also see this related post.)

Update: [17 April 2003] I've added char types to the primitives package, as well as CharIterator/Reader adapters.

This page was generated at 9:56 PM on 15 Jan 2016.
Copyright © 1999 - 2016 Rodney Waldhoff.