I've played around with both the nio file APIs and socket APIs. Though
functional, they are buggy and much harder to use than they really need to
be. For memory mapped file I/O, I wrote my own simple native interface that
uses good ol' byte arrays. It's much simpler to use and I found it to be
faster too. For sockets I took the same approach, again with the same
approach. Easier and faster.
The problem with nio is that it is way overdesigned and imposes special
restrictions on how it is to be used. ByteBuffers, while convient when
writing certain kinds of applications, is a total PITA for anything else.
Try to implement a database or persistent hashtable using nio memory mapped
files. You'll find that sometimes the auto-moving cursor in the ByteBuffers
isn't the desired behavior. Try profiling the app and you'll see tons of
temporary objects being created as well as other useless work being
performed. ByteBuffers should have been designed as a higher level API. Byte
arrays offer much more flexibility.
In my opinion, nio is only good at writing only one application: a web
server. Open FileChannel, read chunks into direct ByteBuffer, flip, spew
contents out a SocketChannel. Even then, it won't scale that well on
platforms that support asyc socket I/O that has advanced beyond the
select/poll model.
It's also a pity that they rewrote the old socket API to use nio internally.
My applications that rely on the old sockets crash under load when running
all versions of jdk1.4. Jdk1.3.x is stable.
Whille nio is better than nothing, don't expect anything better to ever come
bundled with the jdk. We're stuck with it for the remaining lifetime of the
Java platform, and it sucks.