Package org.xnio.channels

# Class NullStreamSinkChannel

java.lang.Object
org.xnio.channels.NullStreamSinkChannel

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `Channel`, `GatheringByteChannel`, `InterruptibleChannel`, `WritableByteChannel`, `CloseableChannel`, `CloseListenerSettable<NullStreamSinkChannel>`, `Configurable`, `StreamSinkChannel`, `SuspendableWriteChannel`, `WriteListenerSettable<NullStreamSinkChannel>`

public final class NullStreamSinkChannel extends Object implements StreamSinkChannel, WriteListenerSettable<NullStreamSinkChannel>, CloseListenerSettable<NullStreamSinkChannel>
A bit-bucket stream sink channel. This channel type is always writable.

Author:
  David M. Lloyd

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.xnio.channels.CloseListenerSettable

`CloseListenerSettable.Setter<C extends Channel>`

## Nested classes/interfaces inherited from interface org.xnio.channels.WriteListenerSettable

`WriteListenerSettable.Setter<C extends Channel>`

## Field Summary

### Fields inherited from interface org.xnio.channels.Configurable

`EMPTY`

## Constructor Summary

Constructors
Constructor
Description
`NullStreamSinkChannel(XnioIoThread thread)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`void`
`awaitWritable()`
Block until this channel becomes writable again.
`void`
`awaitWritable(long time, TimeUnit timeUnit)`
Block until this channel becomes writable again, or until the timeout expires.
`void`
`close()`
Close this channel.
`boolean`
`flush()`
Flush any waiting partial send or write.
`ChannelListener<? super NullStreamSinkChannel>`
`getCloseListener()`
Get the close listener.
`ChannelListener.Setter<NullStreamSinkChannel>`
`getCloseSetter()`
Get the setter which can be used to change the close listener for this channel.
`XnioIoThread`
`getIoThread()`
Get the I/O thread associated with this channel.
`<T> T`
`getOption(Option<T> option)`
Get the value of a channel option.
`XnioWorker`
`getWorker()`
Get the worker for this channel.
`ChannelListener<? super NullStreamSinkChannel>`
`getWriteListener()`
Get the write listener.
`ChannelListener.Setter<NullStreamSinkChannel>`
`getWriteSetter()`
Get the setter which can be used to change the write listener for this channel.
`XnioExecutor`
`getWriteThread()`
Deprecated.
`boolean`
`isOpen()`
Determine whether this channel is open.
`boolean`
`isWriteResumed()`
Determine whether writes are resumed.
`void`
`resumeWrites()`
Resume writes on this channel.
`void`
`setCloseListener(ChannelListener<? super NullStreamSinkChannel> closeListener)`
Set the close listener.
`<T> T`
`setOption(Option<T> option, T value)`
Set an option for this channel.
`void`
`setWriteListener(ChannelListener<? super NullStreamSinkChannel> writeListener)`
Set the write listener.
`void`
`shutdownWrites()`
Indicate that writing is complete for this channel.
`boolean`
`supportsOption(Option<?> option)`
Determine whether an option is supported on this channel.
`void`
`suspendWrites()`
Suspend further write notifications on this channel.
`long`
`transferFrom(FileChannel src, long position, long count)`
Transfer bytes into this channel from the given file.
`long`
`transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer)`
Transfers bytes from the given channel source.
`void`
`wakeupWrites()`
`Resume writes` on this channel, and force the write listener to be triggered even if the channel isn't actually writable.
`int`
`write(ByteBuffer src)`
`long`
`write(ByteBuffer[] srcs)`
`long`
`write(ByteBuffer[] srcs, int offset, int length)`
`int`
`writeFinal(ByteBuffer src)`
Writes some data to the channel, with the same semantics as `WritableByteChannel.write(java.nio.ByteBuffer)`.
`long`
`writeFinal(ByteBuffer[] srcs)`
Writes some data to the channel, with the same semantics as `GatheringByteChannel.write(java.nio.ByteBuffer[])`.
`long`
`writeFinal(ByteBuffer[] srcs, int offset, int length)`
Writes some data to the channel, with the same semantics as `GatheringByteChannel.write(java.nio.ByteBuffer[], int, int)`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### NullStreamSinkChannel

public NullStreamSinkChannel(XnioIoThread thread)
Construct a new instance.

Parameters:
  `thread` - the write thread for this channel

## Method Details

### getWorker

public XnioWorker getWorker()
Description copied from interface: `CloseableChannel`
Get the worker for this channel.

Specified by:
  `getWorker` in interface `CloseableChannel`
Returns:
  the worker

### getIoThread

public XnioIoThread getIoThread()
Description copied from interface: `CloseableChannel`
Get the I/O thread associated with this channel.

Specified by:
  `getIoThread` in interface `CloseableChannel`
Returns:
  the I/O thread associated with this channel

### getWriteThread

@Deprecated public XnioExecutor getWriteThread()
Deprecated.
Description copied from interface: `SuspendableWriteChannel`
Get the write thread for this channel.

Specified by:
  `getWriteThread` in interface `SuspendableWriteChannel`
Returns:
  the thread, or `null` if none is configured or available

### transferFrom

public long transferFrom(FileChannel src, long position, long count) throws IOException
Description copied from interface: `StreamSinkChannel`
Transfer bytes into this channel from the given file. Using this method in preference to `FileChannel.transferTo(long, long, WritableByteChannel)` may provide a performance advantage on some platforms.

If the current thread is interrupted when this method is called, it may throw a `InterruptedIOException`; however, if this exception is thrown, the `InterruptedIOException.bytesTransferred` field is guaranteed to be 0.

Specified by:
  `transferFrom` in interface `StreamSinkChannel`
Parameters:
  `src` - the file to read from
  `position` - the position within the file from which the transfer is to begin
  `count` - the number of bytes to be transferred
Returns:
  the number of bytes (possibly 0) that were actually transferred
Throws:
  `IOException` - if an I/O error occurs

### transferFrom

public long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException
Description copied from interface: `StreamSinkChannel`
Transfers bytes from the given channel source. On some platforms, this may avoid copying bytes between user and kernel space. On other platforms, bytes are passed through the `throughBuffer` parameter's buffer space. On entry, `throughBuffer` will be cleared. On exit, the buffer will be flipped for emptying, and may be empty or may contain data. If this method returns a value less than `count`, then the remaining data in `throughBuffer` may contain data read from `source` which must be written to this channel to complete the operation. Note that using a direct buffer may provide an intermediate performance gain on platforms without zero-copy facilities.

If the current thread is interrupted when this method is called, it may throw a `InterruptedIOException`; however, if this exception is thrown, the `InterruptedIOException.bytesTransferred` field is guaranteed to be 0.

Specified by:
  `transferFrom` in interface `StreamSinkChannel`
Parameters:
  `source` - the source to read from
  `count` - the number of bytes to be transferred
  `throughBuffer` - the buffer to copy through.
Returns:
  the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached
Throws:
  `IOException` - if an I/O error occurs

### setWriteListener

public void setWriteListener(ChannelListener<? super NullStreamSinkChannel> writeListener)
Description copied from interface: `WriteListenerSettable`
Set the write listener.

Specified by:
  `setWriteListener` in interface `WriteListenerSettable<NullStreamSinkChannel>`
Parameters:
  `writeListener` - the write listener

### getWriteListener

public ChannelListener<? super NullStreamSinkChannel> getWriteListener()
Description copied from interface: `WriteListenerSettable`
Get the write listener.

Specified by:
  `getWriteListener` in interface `WriteListenerSettable<NullStreamSinkChannel>`
Returns:
  the write listener

### setCloseListener

public void setCloseListener(ChannelListener<? super NullStreamSinkChannel> closeListener)
Description copied from interface: `CloseListenerSettable`
Set the close listener.

Specified by:
  `setCloseListener` in interface `CloseListenerSettable<NullStreamSinkChannel>`
Parameters:
  `closeListener` - the close listener

### getCloseListener

public ChannelListener<? super NullStreamSinkChannel> getCloseListener()
Description copied from interface: `CloseListenerSettable`
Get the close listener.

Specified by:
  `getCloseListener` in interface `CloseListenerSettable<NullStreamSinkChannel>`
Returns:
  the close listener

### getWriteSetter

public ChannelListener.Setter<NullStreamSinkChannel> getWriteSetter()
Description copied from interface: `StreamSinkChannel`
Get the setter which can be used to change the write listener for this channel.

Specified by:
  `getWriteSetter` in interface `StreamSinkChannel`
Specified by:
  `getWriteSetter` in interface `SuspendableWriteChannel`
Returns:
  the setter

### getCloseSetter

public ChannelListener.Setter<NullStreamSinkChannel> getCloseSetter()
Description copied from interface: `StreamSinkChannel`
Get the setter which can be used to change the close listener for this channel. If the channel is already closed, then the listener will not be called.

Specified by:
  `getCloseSetter` in interface `CloseableChannel`
Specified by:
  `getCloseSetter` in interface `StreamSinkChannel`
Specified by:
  `getCloseSetter` in interface `SuspendableWriteChannel`
Returns:
  the setter

### writeFinal

public int writeFinal(ByteBuffer src) throws IOException
Description copied from interface: `StreamSinkChannel`
Writes some data to the channel, with the same semantics as `WritableByteChannel.write(java.nio.ByteBuffer)`. If all the data is written out then the channel will have its writes shutdown. Semantically this method is equivalent to: `int rem = src.remaining(); int written = channel.write(src); if(written == rem) { channel.shutdownWrites() }` If an exception is thrown the caller is still responsible for closing the channel.

Specified by:
  `writeFinal` in interface `StreamSinkChannel`
Parameters:
  `src` - The data to write
Returns:
  The amount of data that was actually written.
Throws:
  `IOException`
See Also:
  - `WritableByteChannel.write(java.nio.ByteBuffer)`
  - `SuspendableWriteChannel.shutdownWrites()`

### writeFinal

public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException
Description copied from interface: `StreamSinkChannel`
Writes some data to the channel, with the same semantics as `GatheringByteChannel.write(java.nio.ByteBuffer[], int, int)`. If all the data is written out then the channel will have its writes shutdown. If an exception is thrown the caller is still responsible for closing the channel.

Specified by:
  `writeFinal` in interface `StreamSinkChannel`
Parameters:
  `srcs` - The buffers from which bytes are to be retrieved
  `offset` - The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than `srcs.length`
  `length` - The maximum number of buffers to be accessed; must be non-negative and no larger than `srcs.length` - `offset`
Returns:
  The amount of data that was actually written
Throws:
  `IOException`
See Also:
  - `GatheringByteChannel.write(java.nio.ByteBuffer[], int, int)`
  - `SuspendableWriteChannel.shutdownWrites()`

### writeFinal

public long writeFinal(ByteBuffer[] srcs) throws IOException
Description copied from interface: `StreamSinkChannel`
Writes some data to the channel, with the same semantics as `GatheringByteChannel.write(java.nio.ByteBuffer[])`. If all the data is written out then the channel will have its writes shutdown. If an exception is thrown the caller is still responsible for closing the channel.

Specified by:
  `writeFinal` in interface `StreamSinkChannel`
Parameters:
  `srcs` - The buffers from which bytes are to be retrieved
Returns:
  The amount of data that was actually written
Throws:
  `IOException`
See Also:
  - `GatheringByteChannel.write(java.nio.ByteBuffer[])`
  - `SuspendableWriteChannel.shutdownWrites()`

### write

public int write(ByteBuffer src) throws IOException

Specified by:
  `write` in interface `WritableByteChannel`
Throws:
  `IOException`

### write

public long write(ByteBuffer[] srcs) throws IOException

Specified by:
  `write` in interface `GatheringByteChannel`
Throws:
  `IOException`

### write

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

Specified by:
  `write` in interface `GatheringByteChannel`
Throws:
  `IOException`

### suspendWrites

public void suspendWrites()
Description copied from interface: `SuspendableWriteChannel`
Suspend further write notifications on this channel.

Specified by:
  `suspendWrites` in interface `SuspendableWriteChannel`

### resumeWrites

public void resumeWrites()
Description copied from interface: `SuspendableWriteChannel`
Resume writes on this channel. The write listener will be called as soon as the channel becomes writable.

Specified by:
  `resumeWrites` in interface `SuspendableWriteChannel`

### wakeupWrites

public void wakeupWrites()
Description copied from interface: `SuspendableWriteChannel`
`Resume writes` on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

Specified by:
  `wakeupWrites` in interface `SuspendableWriteChannel`

### isWriteResumed

public boolean isWriteResumed()
Description copied from interface: `SuspendableWriteChannel`
Determine whether writes are resumed.

Specified by:
  `isWriteResumed` in interface `SuspendableWriteChannel`
Returns:
  `true` if writes are resumed, `false` if writes are suspended

### shutdownWrites

public void shutdownWrites() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Indicate that writing is complete for this channel. Further attempts to write data to this channel after this method is invoked will result in an exception. If this method was already called, calling this method again will have no additional effect. After this method is called, any remaining data still must be flushed out via the `SuspendableWriteChannel.flush()` method; once this is done, if the read side of the channel was shut down, the channel will automatically close.

Specified by:
  `shutdownWrites` in interface `SuspendableWriteChannel`
Throws:
  `IOException` - if an I/O error occurs

### awaitWritable

public void awaitWritable() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Block until this channel becomes writable again. This method may return spuriously before the channel becomes writable.

Specified by:
  `awaitWritable` in interface `SuspendableWriteChannel`
Throws:
  `IOException` - if an I/O error occurs

### awaitWritable

public void awaitWritable(long time, TimeUnit timeUnit) throws IOException
Description copied from interface: `SuspendableWriteChannel`
Block until this channel becomes writable again, or until the timeout expires. This method may return spuriously before the channel becomes writable or the timeout expires.

Specified by:
  `awaitWritable` in interface `SuspendableWriteChannel`
Parameters:
  `time` - the time to wait
  `timeUnit` - the time unit
Throws:
  `IOException` - if an I/O error occurs

### flush

public boolean flush() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Flush any waiting partial send or write. If there is no data to flush, or if the flush completed successfully, this method will return `true`. If there is data to flush which cannot be immediately written, this method will return `false`. If this method returns `true` after `SuspendableWriteChannel.shutdownWrites()` was called on this channel, the write listener will no longer be invoked on this channel. If this is case and additionally this is a write-only channel or the read side was previously shut down, then the channel will automatically be closed.

Specified by:
  `flush` in interface `SuspendableWriteChannel`
Returns:
  `true` if the message was flushed, or `false` if the result would block
Throws:
  `IOException` - if an I/O error occurs

### isOpen

public boolean isOpen()
Description copied from interface: `SuspendableWriteChannel`
Determine whether this channel is open. This method will return `false` if all directions are shut down, even if there is unflushed write data pending.

Specified by:
  `isOpen` in interface `Channel`
Specified by:
  `isOpen` in interface `SuspendableWriteChannel`
Returns:
  `true` if the channel is open, `false` otherwise

### close

public void close() throws IOException
Description copied from interface: `SuspendableWriteChannel`
Close this channel. If data has been written but not flushed, that data may be discarded, depending on the channel implementation. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Channel`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `CloseableChannel`
Specified by:
  `close` in interface `InterruptibleChannel`
Specified by:
  `close` in interface `SuspendableWriteChannel`
Throws:
  `IOException` - if the close failed

### supportsOption

public boolean supportsOption(Option<?> option)
Description copied from interface: `Configurable`
Determine whether an option is supported on this channel.

Specified by:
  `supportsOption` in interface `Configurable`
Parameters:
  `option` - the option
Returns:
  `true` if it is supported

### getOption

public <T> T getOption(Option<T> option) throws IOException
Description copied from interface: `Configurable`
Get the value of a channel option.

Specified by:
  `getOption` in interface `Configurable`
Type Parameters:
  `T` - the type of the option value
Parameters:
  `option` - the option to get
Returns:
  the value of the option, or `null` if it is not set
Throws:
  `IOException` - if an I/O error occurred when reading the option

### setOption

public <T> T setOption(Option<T> option, T value) throws IllegalArgumentException, IOException
Description copied from interface: `Configurable`
Set an option for this channel. Unsupported options are ignored.

Specified by:
  `setOption` in interface `Configurable`
Type Parameters:
  `T` - the type of the option value
Parameters:
  `option` - the option to set
  `value` - the value of the option to set
Returns:
  the previous option value, if any
Throws:
  `IllegalArgumentException` - if the value is not acceptable for this option
  `IOException` - if an I/O error occurred when modifying the option