APIdia Launch Partner
Top Fields Constructors Methods
sun.nio.ch

pack-priv Class SinkChannelImpl

extends SinkChannel
implements SelChImpl
Class Inheritance
All Implemented Interfaces
sun.nio.ch.SelChImpl, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.FileDescriptor, .IOException, java.nio.ByteBuffer, java.nio.channels.AsynchronousCloseException, .ClosedChannelException, .NotYetConnectedException, .Pipe, .SelectionKey, java.nio.channels.spi.SelectorProvider, java.util.Objects, java.util.concurrent.locks.ReentrantLock

Field Summary

Modifier and TypeField and Description
private final FileDescriptor
private final int
private volatile boolean
private static final NativeDispatcher
private static final int
private static final int
private static final int
private int
private final Object
private final ReentrantLock
private Thread

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
beginWrite(boolean blocking)

Marks the beginning of a write operation that might block.

private void
configureSocketNonBlockingIfVirtualThread()

Ensures that the socket is configured non-blocking when on a virtual thread.

private void
endWrite(boolean blocking, boolean completed)

Marks the end of a write operation that may have blocked.

private void
ensureOpen()

Checks that the channel is open.

public FileDescriptor
public int
private void
implCloseBlockingMode()

Closes this channel when configured in blocking mode.

private void
implCloseNonBlockingMode()

Closes this channel when configured in non-blocking mode.

protected void
implCloseSelectableChannel()

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

Invoked by implCloseChannel to close the channel.

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

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

private boolean
tryClose()

Closes the write end of the pipe if there are no write operation in progress and the channel is not registered with a Selector.

private void
tryFinishClose()

Invokes tryClose to attempt to close the write end of the pipe.

public int
write(ByteBuffer src)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

public long
write(ByteBuffer[] srcs, int offset, int length)

Implements java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

public long
write(ByteBuffer[] srcs)

Implements java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from the given buffers.

Inherited from java.nio.channels.Pipe.SinkChannel:
validOps

Field Detail

fdback to summary
private final FileDescriptor fd
fdValback to summary
private final int fdVal
forcedNonBlockingback to summary
private volatile boolean forcedNonBlocking
ndback to summary
private static final NativeDispatcher nd
ST_CLOSEDback to summary
private static final int ST_CLOSED
ST_CLOSINGback to summary
private static final int ST_CLOSING
ST_INUSEback to summary
private static final int ST_INUSE
stateback to summary
private int state
stateLockback to summary
private final Object stateLock
writeLockback to summary
private final ReentrantLock writeLock
writerThreadback to summary
private Thread writerThread

Constructor Detail

SinkChannelImplback to summary
pack-priv SinkChannelImpl(SelectorProvider sp, FileDescriptor fd) throws IOException

Method Detail

beginWriteback to summary
private void beginWrite(boolean blocking) throws ClosedChannelException

Marks the beginning of a write operation that might block.

Exceptions
ClosedChannelException:
if the channel is closed
NotYetConnectedException:
if the channel is not yet connected
configureSocketNonBlockingIfVirtualThreadback to summary
private void configureSocketNonBlockingIfVirtualThread() throws IOException

Ensures that the socket is configured non-blocking when on a virtual thread.

endWriteback to summary
private void endWrite(boolean blocking, boolean completed) throws AsynchronousCloseException

Marks the end of a write operation that may have blocked.

Exceptions
AsynchronousCloseException:
if the channel was closed due to this thread being interrupted on a blocking write operation.
ensureOpenback to summary
private void ensureOpen() throws ClosedChannelException

Checks that the channel is open.

Exceptions
ClosedChannelException:
if channel is closed (or closing)
getFDback to summary
public FileDescriptor getFD()

Implements sun.nio.ch.SelChImpl.getFD.

getFDValback to summary
public int getFDVal()

Implements sun.nio.ch.SelChImpl.getFDVal.

implCloseBlockingModeback to summary
private void implCloseBlockingMode() throws IOException

Closes this channel when configured in blocking mode. If there is a write operation in progress then the write-end of the pipe is pre-closed and the writer is signalled, in which case the final close is deferred until the writer aborts.

implCloseNonBlockingModeback to summary
private void implCloseNonBlockingMode() throws IOException

Closes this channel when configured in non-blocking mode. If the channel is registered with a Selector then the close is deferred until the channel is flushed from all Selectors.

implCloseSelectableChannelback to summary
protected void implCloseSelectableChannel() throws IOException

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

Invoked by implCloseChannel to close the channel.

Annotations
@Override
Exceptions
IOException:

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

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()

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.

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.

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

translateReadyOpsback to summary
public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski)
tryCloseback to summary
private boolean tryClose() throws IOException

Closes the write end of the pipe if there are no write operation in progress and the channel is not registered with a Selector.

tryFinishCloseback to summary
private void tryFinishClose()

Invokes tryClose to attempt to close the write end of the pipe. This method is used for deferred closing by I/O and Selector operations.

writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

For many types of channels, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer. The write method may need to be invoked more than once to ensure that all remaining bytes are written.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException

Implements java.nio.channels.GatheringByteChannel.write.

Doc from java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from a subsequence of the given buffers.

An attempt is made to write up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

srcs[offset].remaining() + srcs[offset+1].remaining() + ... + srcs[offset+length-1].remaining()
srcs[offset].remaining()
    + srcs[offset+1].remaining()
    + ... + srcs[offset+length-1].remaining()
at the moment that this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. Up to the first srcs[offset].remaining() bytes of this sequence are written from buffer srcs[offset], up to the next srcs[offset+1].remaining() bytes are written from buffer srcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit.

For many types of channels, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer. The write method may need to be invoked more than once to ensure that all remaining bytes are written.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public long write(ByteBuffer[] srcs) throws IOException

Implements java.nio.channels.GatheringByteChannel.write.

Doc from java.nio.channels.GatheringByteChannel.write.

Writes a sequence of bytes to this channel from the given buffers.

An invocation of this method of the form c.write(srcs) behaves in exactly the same manner as the invocation

c.write(srcs, 0, srcs.length);
c.write(srcs, 0, srcs.length);
Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs