Top Description Fields Constructors Methods
org.xnio.channels

public final Class SplitStreamSourceChannel

extends Object
implements StreamSourceChannel, ReadListenerSettable<SplitStreamSourceChannel>, CloseListenerSettable<SplitStreamSourceChannel>
Class Inheritance
All Implemented Interfaces
org.xnio.channels.CloseListenerSettable, org.xnio.channels.ReadListenerSettable, org.xnio.channels.StreamSourceChannel, org.xnio.channels.SuspendableReadChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, java.nio.channels.InterruptibleChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ScatteringByteChannel, java.nio.channels.ReadableByteChannel
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, org.xnio.ChannelListener, .Option, .XnioExecutor, .XnioIoThread, .XnioWorker

A half-duplex (read side) wrapper for a full-duplex channel.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
private ChannelListener<? super SplitStreamSourceChannel>
private final StreamSourceChannel
private static final int
private static final int
private ChannelListener<? super SplitStreamSourceChannel>
private volatile int
private static final AtomicIntegerFieldUpdater<SplitStreamSourceChannel>

Constructor Summary

AccessConstructor and Description
public
SplitStreamSourceChannel(final StreamSourceChannel
the delegate channel
delegate
,
boolean
true to delegate configuration, false otherwise
delegateConfig
)

Construct a new instance.

public
SplitStreamSourceChannel(final StreamSourceChannel
the delegate channel
delegate
)

Construct a new instance which doesn't delegate configuration.

Method Summary

Modifier and TypeMethod and Description
public void
awaitReadable()

Implements org.xnio.channels.SuspendableReadChannel.awaitReadable.

Block until this channel becomes readable again.

public void
awaitReadable(final long
the time to wait
time
,
final TimeUnit
the time unit
timeUnit
)

Implements org.xnio.channels.SuspendableReadChannel.awaitReadable.

Block until this channel becomes readable again, or until the timeout expires.

public void
public ChannelListener<? super SplitStreamSourceChannel>
public ChannelListener.Setter<? extends SplitStreamSourceChannel>
getCloseSetter()

Implements org.xnio.channels.StreamSourceChannel.getCloseSetter.

Get the setter which can be used to change the close listener for this channel.

public XnioIoThread
getIoThread()

Implements org.xnio.channels.CloseableChannel.getIoThread.

Get the I/O thread associated with this channel.

public <T> T
getOption(final Option<T>
the option to get
option
)

Implements org.xnio.channels.Configurable.getOption.

Get the value of a channel option.

public ChannelListener<? super SplitStreamSourceChannel>
public ChannelListener.Setter<? extends SplitStreamSourceChannel>
getReadSetter()

Implements org.xnio.channels.StreamSourceChannel.getReadSetter.

Get the setter which can be used to change the read listener for this channel.

public XnioExecutor
getReadThread()

Implements org.xnio.channels.SuspendableReadChannel.getReadThread.

Deprecated

Get the read thread for this channel.

public XnioWorker
getWorker()

Implements org.xnio.channels.CloseableChannel.getWorker.

Get the worker for this channel.

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

public boolean
isReadResumed()

Implements org.xnio.channels.SuspendableReadChannel.isReadResumed.

Determine whether reads are resumed.

public int
read(final ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

public long
read(final ByteBuffer[]
The buffers into which bytes are to be transferred
dsts
,
final int
The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length
offset
,
final int
The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset
length
)

Implements java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

public long
read(final ByteBuffer[]
The buffers into which bytes are to be transferred
dsts
)

Implements java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into the given buffers.

public void
resumeReads()

Implements org.xnio.channels.SuspendableReadChannel.resumeReads.

Resume reads on this channel.

public void
setCloseListener(final ChannelListener<? super SplitStreamSourceChannel>
the close listener
closeListener
)

Implements org.xnio.channels.CloseListenerSettable.setCloseListener.

Set the close listener.

public <T> T
setOption(final Option<T>
the option to set
option
,
final T
the value of the option to set
value
)

Implements org.xnio.channels.Configurable.setOption.

Set an option for this channel.

public void
setReadListener(final ChannelListener<? super SplitStreamSourceChannel>
the read listener
readListener
)

Implements org.xnio.channels.ReadListenerSettable.setReadListener.

Set the read listener.

public void
shutdownReads()

Implements org.xnio.channels.SuspendableReadChannel.shutdownReads.

Places this readable channel at "end of stream".

public boolean
supportsOption(final Option<?>
the option
option
)

Implements org.xnio.channels.Configurable.supportsOption.

Determine whether an option is supported on this channel.

public void
suspendReads()

Implements org.xnio.channels.SuspendableReadChannel.suspendReads.

Suspend further read notifications on this channel.

public long
transferTo(final long
the position within the file from which the transfer is to begin
position
,
final long
the number of bytes to be transferred
count
,
final FileChannel
the file to write to
target
)

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given file from this channel.

public long
transferTo(final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
,
final StreamSinkChannel
the destination to write to
target
)

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given channel target.

public void
wakeupReads()

Implements org.xnio.channels.SuspendableReadChannel.wakeupReads.

Resume reads on this channel, and force the read listener to be triggered even if the channel isn't actually readable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closeListenerback to summary
private ChannelListener<? super SplitStreamSourceChannel> closeListener
delegateback to summary
private final StreamSourceChannel delegate
FLAG_CLOSEDback to summary
private static final int FLAG_CLOSED
FLAG_DELEGATE_CONFIGback to summary
private static final int FLAG_DELEGATE_CONFIG
readListenerback to summary
private ChannelListener<? super SplitStreamSourceChannel> readListener
stateback to summary
private volatile int state
stateUpdaterback to summary
private static final AtomicIntegerFieldUpdater<SplitStreamSourceChannel> stateUpdater

Constructor Detail

SplitStreamSourceChannelback to summary
public SplitStreamSourceChannel(final StreamSourceChannel delegate, boolean delegateConfig)

Construct a new instance.

Parameters
delegate:StreamSourceChannel

the delegate channel

delegateConfig:boolean

true to delegate configuration, false otherwise

SplitStreamSourceChannelback to summary
public SplitStreamSourceChannel(final StreamSourceChannel delegate)

Construct a new instance which doesn't delegate configuration.

Parameters
delegate:StreamSourceChannel

the delegate channel

Method Detail

awaitReadableback to summary
public void awaitReadable() throws IOException

Implements org.xnio.channels.SuspendableReadChannel.awaitReadable.

Doc from org.xnio.channels.SuspendableReadChannel.awaitReadable.

Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.

Exceptions
IOException:
if an I/O error occurs
awaitReadableback to summary
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException

Implements org.xnio.channels.SuspendableReadChannel.awaitReadable.

Doc from org.xnio.channels.SuspendableReadChannel.awaitReadable.

Block until this channel becomes readable again, or until the timeout expires. This method may return spuriously before the channel becomes readable or the timeout expires.

Parameters
time:long

the time to wait

timeUnit:TimeUnit

the time unit

Exceptions
IOException:
if an I/O error occurs
closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close, org.xnio.channels.CloseableChannel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Exceptions
IOException:
If an I/O error occurs
getCloseListenerback to summary
public ChannelListener<? super SplitStreamSourceChannel> getCloseListener()

Implements org.xnio.channels.CloseListenerSettable.getCloseListener.

Doc from org.xnio.channels.CloseListenerSettable.getCloseListener.

Get the close listener.

Returns:ChannelListener<? super SplitStreamSourceChannel>

the close listener

getCloseSetterback to summary
public ChannelListener.Setter<? extends SplitStreamSourceChannel> getCloseSetter()

Implements org.xnio.channels.StreamSourceChannel.getCloseSetter.

Doc from org.xnio.channels.StreamSourceChannel.getCloseSetter.

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.

Returns:ChannelListener.Setter<? extends SplitStreamSourceChannel>

Doc from org.xnio.channels.CloseableChannel.getCloseSetter.

the setter

getIoThreadback to summary
public XnioIoThread getIoThread()

Implements org.xnio.channels.CloseableChannel.getIoThread.

Doc from org.xnio.channels.CloseableChannel.getIoThread.

Get the I/O thread associated with this channel.

Returns:XnioIoThread

the I/O thread associated with this channel

getOptionback to summary
public <T> T getOption(final Option<T> option) throws IOException

Implements org.xnio.channels.Configurable.getOption.

Doc from org.xnio.channels.Configurable.getOption.

Get the value of a channel option.

Parameters
<T>
the type of the option value
option:Option<T>

the option to get

Returns:T

the value of the option, or null if it is not set

Exceptions
IOException:
if an I/O error occurred when reading the option
getReadListenerback to summary
public ChannelListener<? super SplitStreamSourceChannel> getReadListener()

Implements org.xnio.channels.ReadListenerSettable.getReadListener.

Doc from org.xnio.channels.ReadListenerSettable.getReadListener.

Get the read listener.

Returns:ChannelListener<? super SplitStreamSourceChannel>

the read listener

getReadSetterback to summary
public ChannelListener.Setter<? extends SplitStreamSourceChannel> getReadSetter()

Implements org.xnio.channels.StreamSourceChannel.getReadSetter.

Doc from org.xnio.channels.StreamSourceChannel.getReadSetter.

Get the setter which can be used to change the read listener for this channel.

Returns:ChannelListener.Setter<? extends SplitStreamSourceChannel>

Doc from org.xnio.channels.SuspendableReadChannel.getReadSetter.

the setter

getReadThreadback to summary
public XnioExecutor getReadThread()

Implements org.xnio.channels.SuspendableReadChannel.getReadThread.

Doc from org.xnio.channels.SuspendableReadChannel.getReadThread.

Deprecated

Get the read thread for this channel.

Returns:XnioExecutor

the thread, or null if none is configured or available

Annotations
@Deprecated
getWorkerback to summary
public XnioWorker getWorker()

Implements org.xnio.channels.CloseableChannel.getWorker.

Doc from org.xnio.channels.CloseableChannel.getWorker.

Get the worker for this channel.

Returns:XnioWorker

the worker

isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

isReadResumedback to summary
public boolean isReadResumed()

Implements org.xnio.channels.SuspendableReadChannel.isReadResumed.

Doc from org.xnio.channels.SuspendableReadChannel.isReadResumed.

Determine whether reads are resumed.

Returns:boolean

true if reads are resumed, false if reads are suspended

readback to summary
public int read(final ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

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

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

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

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

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Exceptions
IOException:
If some other I/O error occurs
readback to summary
public long read(final ByteBuffer[] dsts, final int offset, final int length) throws IOException

Implements java.nio.channels.ScatteringByteChannel.read.

Doc from java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

An invocation of this method attempts to read up to r bytes from this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

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

Suppose that a byte sequence of length n is read, where 0 <= n <= r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into 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.

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

Parameters
dsts:ByteBuffer[]

The buffers into which bytes are to be transferred

offset:int

The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset

Returns:long

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Exceptions
IOException:
If some other I/O error occurs
readback to summary
public long read(final ByteBuffer[] dsts) throws IOException

Implements java.nio.channels.ScatteringByteChannel.read.

Doc from java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into the given buffers.

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

c.read(dsts, 0, dsts.length);
c.read(dsts, 0, dsts.length);
Parameters
dsts:ByteBuffer[]

The buffers into which bytes are to be transferred

Returns:long

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Exceptions
IOException:
If some other I/O error occurs
resumeReadsback to summary
public void resumeReads()

Implements org.xnio.channels.SuspendableReadChannel.resumeReads.

Doc from org.xnio.channels.SuspendableReadChannel.resumeReads.

Resume reads on this channel. The read listener will be called as soon as there is data available to be read.

setCloseListenerback to summary
public void setCloseListener(final ChannelListener<? super SplitStreamSourceChannel> closeListener)

Implements org.xnio.channels.CloseListenerSettable.setCloseListener.

Doc from org.xnio.channels.CloseListenerSettable.setCloseListener.

Set the close listener.

Parameters
closeListener:ChannelListener<? super SplitStreamSourceChannel>

the close listener

setOptionback to summary
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException

Implements org.xnio.channels.Configurable.setOption.

Doc from org.xnio.channels.Configurable.setOption.

Set an option for this channel. Unsupported options are ignored.

Parameters
<T>
the type of the option value
option:Option<T>

the option to set

value:T

the value of the option to set

Returns:T

the previous option value, if any

Exceptions
IllegalArgumentException:
if the value is not acceptable for this option
IOException:
if an I/O error occurred when modifying the option
setReadListenerback to summary
public void setReadListener(final ChannelListener<? super SplitStreamSourceChannel> readListener)

Implements org.xnio.channels.ReadListenerSettable.setReadListener.

Doc from org.xnio.channels.ReadListenerSettable.setReadListener.

Set the read listener.

Parameters
readListener:ChannelListener<? super SplitStreamSourceChannel>

the read listener

shutdownReadsback to summary
public void shutdownReads() throws IOException

Implements org.xnio.channels.SuspendableReadChannel.shutdownReads.

Doc from org.xnio.channels.SuspendableReadChannel.shutdownReads.

Places this readable channel at "end of stream". Further reads will result in EOF. Shutting down all directions of a channel will cause close() to be called automatically.

Exceptions
IOException:
if an I/O error occurs
supportsOptionback to summary
public boolean supportsOption(final Option<?> option)

Implements org.xnio.channels.Configurable.supportsOption.

Doc from org.xnio.channels.Configurable.supportsOption.

Determine whether an option is supported on this channel.

Parameters
option:Option<?>

the option

Returns:boolean

true if it is supported

suspendReadsback to summary
public void suspendReads()

Implements org.xnio.channels.SuspendableReadChannel.suspendReads.

Doc from org.xnio.channels.SuspendableReadChannel.suspendReads.

Suspend further read notifications on this channel.

transferToback to summary
public long transferTo(final long position, final long count, final FileChannel target) throws IOException

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Doc from org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given file from this channel. Using this method in preference to FileChannel#transferFrom(ReadableByteChannel, long, long) may provide a performance advantage on some platforms.

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

Parameters
position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

target:FileChannel

the file to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred

Exceptions
IOException:
if an I/O error occurs
transferToback to summary
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Doc from org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given channel target. 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 possibly 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 this channel which must be written to target 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 java.io.InterruptedIOException; however, if this exception is thrown, the java.io.InterruptedIOException#bytesTransferred field is guaranteed to be 0. Note that the return value is the amount of data that was actually transferred to the StreamSinkChannel. The actual amount of data read could be larger than this, and can be calculated by adding the return value and the amount of data left in throughBuffer.

Parameters
count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

target:StreamSinkChannel

the destination to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Exceptions
IOException:
if an I/O error occurs
wakeupReadsback to summary
public void wakeupReads()

Implements org.xnio.channels.SuspendableReadChannel.wakeupReads.

Doc from org.xnio.channels.SuspendableReadChannel.wakeupReads.

Resume reads on this channel, and force the read listener to be triggered even if the channel isn't actually readable.