Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

Name

Package java.nio.channels

Synopsis

This package is at the heart of the NIO API. A channel is a communication channel for transferring bytes from or to a java.nio.ByteBuffer. Channels serve a similar purpose to the InputStream and OutputStream classes of the java.io package, but are completely unrelated to those classes, and provide important features not available with the java.io API. The Channels class defines methods that bridge the java.io and java.nio.channels APIs, by returning channels based on streams and streams based on channels.

The Channel interface simply defines methods for testing whether a channel is open and for closing a channel. The other interfaces in the package extend Channel and define read( ) and write( ) methods for reading bytes from the channel into one or more byte buffers and for writing bytes from one or more byte buffers to the channel.

The FileChannel class defines an channel-based API for reading and writing from files (and also provides other important file functionality such as file locking and memory mapping that is not available through the java.io package). SocketChannel, ServerSocketChannel, and DatagramChannel are channels for communication over a network, and Pipe defines two inner classes that use the channel abstraction for communication between threads.

The network and pipe channels are all subclasses of the SelectableChannel class, and may be put into nonblocking mode, in which calls to read( ) and write( ) return immediately, even ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page