今回は、J2SE 1.4.0の話からはじめましょう。
J2SE 1.4.0がリリースされたのが2002年。すでに9年も経ってしまいました。
さすがに最近こそ使われなくなったものの、日本においてはJ2SE 1.4.xが一番多く使われていたバージョンなのではないでしょうか。
そのJ2SE 1.4.0の時に新機能として導入されたのが、JSR 51 New I/O APIs for the Java Platform、通称NIOです。
NIOは、java.ioを補う新しいI/Oに関するAPIで、入出力に特化したバッファや、ストリームよりも高効率なチャネルなどを提供しています。また、ノンブロッキングI/OもNIOで導入されました。
NIOは一般にはそれほど使われていないようですが、GlassFishやTomcatなど多くのフレームワークやライブラリで導入されています。
しかし、JSR 51は当初から積み残しがありました。JSR 51のリクエスト、つまり当初スコープに入っていた機能を以下に示します。
- An API for scalable I/O operations on both files and sockets, in the form of either asynchronous requests or polling;
- An API for fast buffered binary I/O, including the ability to map files into memory when that is supported by the underlying platform;
- An API for fast buffered character I/O, including a simple parsing facility based upon regular expressions and a simple printf-style formatting facility;
- An API for character-set converters, including a service-provider interface for pluggable converters;
- A rich yet platform-independent set of I/O exceptions; and
- A new filesystem interface that supports bulk access to file attributes (including MIME content types), escape to filesystem-specific APIs, and a service-provider interface for pluggable filesystem implementations.
太文字の部分は筆者が強調のために付け加えました。この太字の部分が積み残しの部分です。つまり、次の2つの機能が積み残しになっていました。
- 非同期I/O
- 新しいファイルシステムインタフェース
また、以下の機能も当初スコープに入っていたのですが、実装されませんでした。
- SocketChannelにおけるマルチキャスト
そこで、J2SE 1.4がリリースされた後、これらの積み残しに対応するために策定されたのが、JSR 203 More New I/O APIs for the Java Platform ("NIO.2")です。
JSR 203のリクエストを次に示します。
- A new filesystem interface that supports bulk access to file attributes, change notification, escape to filesystem-specific APIs, and a service-provider interface for pluggable filesystem implementations;
- An API for asynchronous (as opposed to polled, non-blocking) I/O operations on both sockets and files; and
- The completion of the socket-channel functionality defined in JSR-51, including the addition of support for binding, option configuration, and multicast datagrams.
それぞれ、上からファイルシステムインタフェース、非同期I/O、マルチキャストに相当することがわかります。
もともとJSR 203はJ2SE 5.0への導入を目指していたのですが、結局Java SE 7で導入されることが決まりました。
そこで、今月から数回にわたってNIO2を紹介していきます。今月はファイルシステムインタフェースの基本的な機能について紹介します。
なお、JSR 203のスペックリードはOracleのAlan Bateman氏が務めています。前回紹介したFork/Join FrameworkのスペックリードであるDoug Lea氏もエキスパートグループのメンバです。
ちなみにJSR 51のスペックリードはMark Reinhold氏でした。そう、現在Java SE 7全体の仕様を決めるJSR 336のスペックリードであるMark Reinhold氏です。
また、日本からは風間一洋氏が、JSR 51に引き続きJSR 203でもエキスパートグループのメンバを務められています。