This post originated from an RSS feed registered with Java Buzz
by Rod Waldhoff.
Original Post: I/O Iterators for Java
Feed Title: Rod Waldhoff: Java Channel
Feed URL: http://radio-weblogs.com/0122027/categories/java/rss.xml
Feed Description: about the Java programming language
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 functoralgorithms 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.