Java NIO PDF Print E-mail

by Ron Hitchens
Published by O'Reilly

Review by David Young

At only six chapters and 282 pages (including the index), the size of O'Reilly's book, "Java NIO" (short for "New I/O") published in August 2002 by Ron Hichens, might lead one to think it is little more than a cursory examination of the NIO packages introduced in J2SE 1.4 as a response to the Java Specification Request (JSR) #51. Yet, despite its relatively compact size, Mr. Hichens has done a very good job of introducing and explaining the many aspects of this New I/O. The book even includes parts of JSR 51 that are only tangentially related to I/O, such as the new regular expression processing found in java.util.regex and the new pluggable character set mappings.

Chapter 1 is a primer on general I/O concepts and mechanisms and provides a useful foundation for the following information. Beginning with the basics as a foundation is a strategy that Mr. Hichens uses in each of the subjects in the following chapters. It's an important first step, often omitted in books more interested in prose than instruction.

Chapter 2 is a thorough explanation of the various Buffer classes. As the means for data accumulation and manipulation, Buffers are a natural first step in explaining the NIO package. It starts with a fairly detailed basic description followed with sections labeled: Creating, Accessing, Filling, Flipping, Draining, Compacting, Marking, Comparing, Bulk Moves, Duplicating, etc. Each section provides simple yet useful examples of the various operations along with some helpful hints on potential pitfalls.

Chapter 3 adds about all you'd want to know about the channels used to convey the data into and out of buffer. As the book explains, Channels "are not an extension or enhancement, but a new, first-class Java I/O paradigm. … A Channel is a conduit that transports data efficiently between byte buffers and the entity on the other end of the channel (usually a file or socket)." In the ensuing sections: Scatter/Gather, File Channels, Memory-Mapped Files, Socket Channels, Pipes and The Channel Utility Classes, he explains the use of channels within the NIO paradigm.

Chapter 4 covers Selectors. Selectors add another completely new ability to Java 1.4. With selectors Java now has a much more sophisticated and integrated ability to do asynchronous and multiplexed I/O. This is obviously very important to anyone dealing with real-time and/or high-demand I/O and it is one of the main reasons for JSR 51.

Again, the book does a very good job of explaining the concept and use of Selectors in chapter sections entitled: The Selection Process, Stopping the Selection Process, Managing Selection Keys, Concurrency, Asynchronous Closability and Selection Scaling.

Chapter 5 introduces and explains the use of the new java.util.regex package. Regular expression processing was part of the JSR 51 and thus part of this book. While not strictly I/O related, as anyone who's used Perl can attest, regular expression processing is very useful when it comes to manipulating any textual data that one uses in I/O.

It should be noted that while the book covers the Java Regular Expression API very well, it's not sufficient to introduce someone to the many intricacies of regular expressions. Of course O'Reilly has that covered in Jeffrey Friedl's book, "Mastering Regular Expressions."

In the last chapter, Chapter 6, "Character Sets", the book presents a pretty close examination of the actual data moved in I/O and how it is abstracted in Java 1.4 in the class Charset. If you've ever wondered about character sets are involved in character encoding or how one character set might be compared with or encoded into another, this chapter will go a long way toward filling you in.

The book concludes with three appendices:

  • NIO and the JNI - A more detailed explanation of a new Java ability to use system memory allocated with native (JNI) code. This is one way they managed to improve the performance of Java real-time 3D applications so dramatically.
  •  

  • Selectable Channels Service Provider Interface (SPI) - Basically explains why this API is beyond the scope of the book and why it wouldn't be useful to anyone not programming a JVM or high-performance App server.
  •  

  • NIO Quick Reference - Just as the name implies.
In summation, the concepts range from basic to quite advanced yet are presented in such a way that, even while being explained, the information is understandable and can be accessed for reference purposes. The examples are simple yet useful in demonstrating the concepts and the implementation of them. The style is informative and complete yet very accessible and informal. Overall, a well written and useful book to anyone needing to know the usefulness and basic workings of the NIO packages.
 
< Prev   Next >
Colocation provided by VersaServers