|
New I/O APIs |
Documentation Contents |
The new I/O (NIO) APIs introduced in v 1.4 provide new features and improved performance in the areas of buffer management, scalable network and file I/O, character-set support, and regular-expression matching. The NIO APIs supplement the I/O facilities in thejava.iopackage.Features
The NIO APIs include the following features:
- Buffers for data of primitive types
- Character-set encoders and decoders
- A pattern-matching facility based on Perl-style regular expressions
- Channels, a new primitive I/O abstraction
- A file interface that supports locks and memory mapping
- A multiplexed, non-blocking I/O facility for writing scalable servers
Examples
API References
New packages, classes, and interfaces:
java.niopackage: Buffers, which are used throughout the NIO APIs.java.nio.channelspackage: Channels and selectors.java.nio.charsetpackage: Character encodings.java.nio.channels.spipackage: Service-provider classes for channels.java.nio.charset.spipackage: Service-provider classes for charsets.java.util.regexpackage: Classes for matching character sequences against patterns specified by regular expressions.java.lang.CharSequenceinterface: The interface implemented by objects that can be passed as arguments to methods in thejava.util.regexpackage. TheString,StringBuffer, andjava.nio.CharBufferclasses implement this interface.Note: The new
InetSocketAddressandSocketAddressclasses, while not strictly part of the NIO APIs, are used by them.Revised classes and interfaces:
- In the
FileInputStream,FileOutputStream, andRandomAccessFileclasses,getChannelmethods have been added to return the underlyingFileChannelobject, and theclosemethods have been revised to close the underlying channel.- In the
InputStreamReaderandOutputStreamWriterclasses, constructors have been added that take a stream and aCharsetobject, and thegetEncodingmethods have been revised to return the historical name of the encoding being used.- In the
Stringclass, twosplitmethods are new. ThesubSequencemethod has been added, as required by theCharSequenceinterface thatStringnow implements.- In the
StringBufferclass, thesubSequencemethod has been added, as required by theCharSequenceinterface thatStringBuffernow implements.- In the
Threadclass, theinterruptmethod has been revised to interrupt threads blocked in channel-I/O operations.- In the
DatagramSocketclass, thereceiveandsendmethods have been revised to throw ajava.nio.channels.IllegalBlockingModeExceptionif the socket has a channel and the channel is in non-blocking mode. Theclosemethod now closes the socket's channel, if it has one, and the newgetChannelmethod returns the underlying channel, if any.- In the
ServerSocketclass, theacceptandimplAcceptmethods have been revised to throw ajava.nio.IllegalBlockingModeExceptionif the socket has a channel and the channel is in non-blocking mode. ThegetChannelmethod has been added andcloserevised, for the same reasons as inDatagramSocket.- In the
Socketclass, thegetInputStreamandgetOutputStreammethods have been revised to delegate all I/O operations to the socket's channel, if it has one. Theconnectmethods have been revised to throw ajava.nio.IllegalBlockingModeExceptionif the socket has a channel and the channel is in non-blocking mode. ThegetChannelmethod has been added andcloserevised, for the same reasons as inDatagramSocket.Note: Three new functions have been added to the Java Native Interface (JNI) to support direct buffers. For information, see JNI Enhancements in v 1.4.
For More Information
Located on the Java Software web site:
- JSR-51: New I/O APIs for the Java Platform (Note: v 1.4 has a subset of the changes proposed in this specification request.)
|
Copyright © 1999-2001 Sun Microsystems, Inc. All Rights Reserved. |
Java Software |