APIdia Launch Partner
Top Description Inners Constructors Methods
jdk.nio

public final Class Channels

extends Object
Class Inheritance
Imports
java.io.FileDescriptor, .IOException, java.nio.channels.SelectableChannel, .SelectionKey, java.nio.channels.spi.AbstractSelectableChannel, .SelectorProvider, java.util.Objects, sun.nio.ch.IOUtil, .Net, .SelChImpl, .SelectionKeyImpl, .SelectorProviderImpl

Defines static methods to create channels.

Unless otherwise specified, passing a null argument to any of the methods defined here will cause a NullPointerException to be thrown.

Since
11

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static interface
Channels.SelectableChannelCloser

An object used to coordinate the closing of a selectable channel created by readWriteSelectableChannel.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SelectableChannel

Returns:

The selectable channel
readWriteSelectableChannel
(FileDescriptor
The file descriptor
fd
,
Channels.SelectableChannelCloser
The object to close the channel
closer
)

Creates a selectable channel to a file descriptor that supports an operation-set of OP_READ and OP_WRITE.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Channelsback to summary
private Channels()

Method Detail

readWriteSelectableChannelback to summary
public static SelectableChannel readWriteSelectableChannel(FileDescriptor fd, Channels.SelectableChannelCloser closer)

Creates a selectable channel to a file descriptor that supports an operation-set of OP_READ and OP_WRITE. The selectable channel will be created by the default SelectorProvider.

The given file descriptor is a socket or resource that can be multiplexed by a java.nio.channels.Selector for read and write readiness. Great care is required to coordinate direct use of the file descriptor with the use of the selectable channel. In particular, changing the blocking mode or closing the file descriptor without careful coordination will result in unspecified and unsafe side effects. The given SelectableChannelCloser is invoked to close the file descriptor and to coordinate the closing when the channel is registered with a Selector.

Implementation Note

This method throws UnsupportedOperationException if the default SelectorProvider is not the JDK built-in implementation.

Parameters
fd:FileDescriptor

The file descriptor

closer:Channels.SelectableChannelCloser

The object to close the channel

Returns:SelectableChannel

The selectable channel

Exceptions
IllegalArgumentException:
If the file descriptor is not valid
jdk.nio back to summary

private final Class Channels.ReadWriteChannelImpl

extends AbstractSelectableChannel
implements SelChImpl
Class Inheritance
All Implemented Interfaces
sun.nio.ch.SelChImpl, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
private final Channels.SelectableChannelCloser
private final FileDescriptor
private final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public FileDescriptor
public int
protected void
protected void
implConfigureBlocking(boolean block)

Implements abstract java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking.

Adjusts this channel's blocking mode.

public void
public boolean
translateAndSetReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndSetReadyOps.

Sets the specified ops if present in interestOps.

public boolean
translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndUpdateReadyOps.

Adds the specified ops if present in interestOps.

public int
translateInterestOps(int ops)

Implements sun.nio.ch.SelChImpl.translateInterestOps.

Translates an interest operation set into a native event set

private boolean
translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)

public int
validOps()

Implements abstract java.nio.channels.SelectableChannel.validOps.

Returns an operation set identifying this channel's supported operations.

Inherited from java.nio.channels.spi.AbstractSelectableChannel:
blockingLockconfigureBlockingimplCloseChannelisBlockingisRegisteredkeyForproviderregister

Field Detail

closerback to summary
private final Channels.SelectableChannelCloser closer
fdback to summary
private final FileDescriptor fd
fdValback to summary
private final int fdVal

Constructor Detail

ReadWriteChannelImplback to summary
pack-priv ReadWriteChannelImpl(SelectorProviderImpl provider, FileDescriptor fd, Channels.SelectableChannelCloser closer)

Method Detail

getFDback to summary
public FileDescriptor getFD()

Implements sun.nio.ch.SelChImpl.getFD.

Annotations
@Override
getFDValback to summary
public int getFDVal()

Implements sun.nio.ch.SelChImpl.getFDVal.

Annotations
@Override
implCloseSelectableChannelback to summary
protected void implCloseSelectableChannel() throws IOException

Implements abstract java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel.

Doc from java.nio.channels.spi.AbstractSelectableChannel.implCloseSelectableChannel.

Closes this selectable channel.

This method is invoked by the close method in order to perform the actual work of closing the channel. This method is only invoked if the channel has not yet been closed, and it is never invoked more than once.

An implementation of this method must arrange for any other thread that is blocked in an I/O operation upon this channel to return immediately, either by throwing an exception or by returning normally.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
implConfigureBlockingback to summary
protected void implConfigureBlocking(boolean block) throws IOException

Implements abstract java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking.

Doc from java.nio.channels.spi.AbstractSelectableChannel.implConfigureBlocking.

Adjusts this channel's blocking mode.

This method is invoked by the configureBlocking method in order to perform the actual work of changing the blocking mode. This method is only invoked if the new mode is different from the current mode.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
killback to summary
public void kill() throws IOException

Implements sun.nio.ch.SelChImpl.kill.

Annotations
@Override
translateAndSetReadyOpsback to summary
public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndSetReadyOps.

Doc from sun.nio.ch.SelChImpl.translateAndSetReadyOps.

Sets the specified ops if present in interestOps. The specified ops are turned on, and all other ops are turned off.

Annotations
@Override
translateAndUpdateReadyOpsback to summary
public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski)

Implements sun.nio.ch.SelChImpl.translateAndUpdateReadyOps.

Doc from sun.nio.ch.SelChImpl.translateAndUpdateReadyOps.

Adds the specified ops if present in interestOps. The specified ops are turned on without affecting the other ops.

Annotations
@Override
translateInterestOpsback to summary
public int translateInterestOps(int ops)

Implements sun.nio.ch.SelChImpl.translateInterestOps.

Doc from sun.nio.ch.SelChImpl.translateInterestOps.

Translates an interest operation set into a native event set

Annotations
@Override
translateReadyOpsback to summary
private boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)
validOpsback to summary
public int validOps()

Implements abstract java.nio.channels.SelectableChannel.validOps.

Doc from java.nio.channels.SelectableChannel.validOps.

Returns an operation set identifying this channel's supported operations. The bits that are set in this integer value denote exactly the operations that are valid for this channel. This method always returns the same value for a given concrete channel class.

Annotations
@Override
jdk.nio back to summary

public Interface Channels.SelectableChannelCloser


An object used to coordinate the closing of a selectable channel created by readWriteSelectableChannel.
Since
11

Method Summary

Modifier and TypeMethod and Description
public void
implCloseChannel(SelectableChannel
The selectable channel
sc
)

Closes a selectable channel.

public void
implReleaseChannel(SelectableChannel
The closed selectable channel
sc
)

Release the file descriptor and any resources for a selectable channel that closed while registered with one or more Selectors.

Method Detail

implCloseChannelback to summary
public void implCloseChannel(SelectableChannel sc) throws IOException

Closes a selectable channel.

This method is invoked by the channel's close method in order to perform the actual work of closing the channel. This method is only invoked if the channel has not yet been closed, and it is never invoked more than once by the channel's close implementation.

An implementation of this method must arrange for any other thread that is blocked in an I/O operation upon the channel to return immediately, either by throwing an exception or by returning normally. If the channel is registered with one or more Selectors then the file descriptor should not be released until the implReleaseChannel method is invoked.

Parameters
sc:SelectableChannel

The selectable channel

Exceptions
IOException:
If an I/O error occurs while closing the file descriptor
See Also
java.nio.channels.spi.AbstractInterruptibleChannel#implCloseChannel
implReleaseChannelback to summary
public void implReleaseChannel(SelectableChannel sc) throws IOException

Release the file descriptor and any resources for a selectable channel that closed while registered with one or more Selectors.

This method is for cases where a channel is closed when registered with one or more Selectors. A channel may remain registered for some time after it is closed. This method is invoked when the channel is eventually deregistered from the last Selector that it was registered with. It is invoked at most once.

API Note

This method is invoked while synchronized on the selector and its selected-key set. Great care must be taken to avoid deadlocks with other threads that also synchronize on these objects.

Parameters
sc:SelectableChannel

The closed selectable channel

Exceptions
IOException:
If an I/O error occurs
See Also
java.nio.channels.spi.AbstractSelector#deregister