This subinterface of Channel defines a single key write( ) method which writes bytes from a specified ByteBuffer (updating the buffer position as it goes) to the channel. If possible, it writes all remaining bytes in the buffer (see Buffer.remaining( ) ). This is not always possible (with nonblocking channels, for example) so the write( ) method returns the number of bytes that it was actually able to write to the channel. write( ) is declared to throw an IOException . More specifically , it may throw a ClosedChannelException if the channel is closed. If the channel is closed asynchronously, or if a blocked thread is interrupted , the write( ) method may terminate with an AsynchronousCloseException or a ClosedByInterruptException . write( ) may also throw an unchecked NonWritableChannelException if it is called on a channel (such as a FileChannel ) that was not opened or configured to allow writing. WritableByteChannel implementations are required to be thread-safe: only one thread may perform a write operation on a channel at a time. If a write operation is in progress, then any call to write( ) will block until the in-progress operation completes. Some channel implementations may allow read and write operations to proceed concurrently; some may not. Figure 13-42. java.nio.channels.WritableByteChannelpublic interface WritableByteChannel extends Channel { // Public Instance Methods int write (java.nio.ByteBuffer src ) throws java.io.IOException; } ImplementationsByteChannel , GatheringByteChannel , Pipe.SinkChannel Passed ToChannels.{newOutputStream( ) , newWriter( )} , FileChannel.transferTo( ) Returned ByChannels.newChannel( ) |