Top Description Fields Constructors Methods
org.xnio.channels

public Class AssembledStreamChannel

extends Object
implements StreamChannel
Class Inheritance
All Implemented Interfaces
org.xnio.channels.StreamChannel, org.xnio.channels.ByteChannel, java.nio.channels.ScatteringByteChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.GatheringByteChannel, java.nio.channels.WritableByteChannel, java.nio.channels.ByteChannel, org.xnio.channels.StreamSourceChannel, org.xnio.channels.SuspendableReadChannel, org.xnio.channels.CloseableChannel, org.xnio.channels.Configurable, java.nio.channels.InterruptibleChannel, org.xnio.channels.StreamSinkChannel, org.xnio.channels.SuspendableWriteChannel, org.xnio.channels.SuspendableChannel
Known Direct Subclasses
org.xnio.channels.AssembledConnectedStreamChannel
Static Imports
org.xnio._private.Messages.msg

A stream channel assembled from a stream source and stream sink.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
private final CloseableChannel
private final ChannelListener.Setter<AssembledStreamChannel>
private final ChannelListener.Setter<AssembledStreamChannel>
private final StreamSinkChannel
private final StreamSourceChannel
private final ChannelListener.Setter<AssembledStreamChannel>

Constructor Summary

AccessConstructor and Description
public
AssembledStreamChannel(final CloseableChannel
the single central closeable channel
closeable
,
final StreamSourceChannel
the stream source channel
source
,
final StreamSinkChannel
the stream sink channel
sink
)

Construct a new instance.

public
AssembledStreamChannel(final StreamSourceChannel
the stream source channel
source
,
final StreamSinkChannel
the stream sink channel
sink
)

Construct a new instance.

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

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Block until this channel becomes writable again.

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

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

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

public void
public boolean
flush()

Implements org.xnio.channels.SuspendableWriteChannel.flush.

Flush any waiting partial send or write.

public ChannelListener.Setter<? extends AssembledStreamChannel>
getCloseSetter()

Implements org.xnio.channels.StreamChannel.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.Setter<? extends AssembledStreamChannel>
getReadSetter()

Implements org.xnio.channels.StreamChannel.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 ChannelListener.Setter<? extends AssembledStreamChannel>
getWriteSetter()

Implements org.xnio.channels.StreamChannel.getWriteSetter.

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

public XnioExecutor
getWriteThread()

Implements org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Deprecated

Get the write thread for this channel.

public boolean
public boolean
isReadResumed()

Implements org.xnio.channels.SuspendableReadChannel.isReadResumed.

Determine whether reads are resumed.

public boolean
isWriteResumed()

Implements org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Determine whether writes 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
resumeWrites()

Implements org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Resume writes on this channel.

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

Implements org.xnio.channels.SuspendableReadChannel.shutdownReads.

Places this readable channel at "end of stream".

public void
shutdownWrites()

Implements org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

Indicate that writing is complete for this channel.

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

Implements org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Suspend further write notifications on this channel.

public long
transferFrom(final FileChannel
the file to read from
src
,
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
)

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Transfer bytes into this channel from the given file.

public long
transferFrom(final StreamSourceChannel
the source to read from
source
,
final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
)

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Transfers bytes from the given channel source.

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.

public void
wakeupWrites()

Implements org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Resume writes on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

public int
write(final ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

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

public long
write(final ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
final int
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
offset
,
final int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
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(final ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

Implements java.nio.channels.GatheringByteChannel.write.

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

public int
writeFinal(ByteBuffer
The data to write
src
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
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
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer[], int, int).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as write(java.nio.ByteBuffer[]).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closeableback to summary
private final CloseableChannel closeable
closeSetterback to summary
private final ChannelListener.Setter<AssembledStreamChannel> closeSetter
readSetterback to summary
private final ChannelListener.Setter<AssembledStreamChannel> readSetter
sinkback to summary
private final StreamSinkChannel sink
sourceback to summary
private final StreamSourceChannel source
writeSetterback to summary
private final ChannelListener.Setter<AssembledStreamChannel> writeSetter

Constructor Detail

AssembledStreamChannelback to summary
public AssembledStreamChannel(final CloseableChannel closeable, final StreamSourceChannel source, final StreamSinkChannel sink)

Construct a new instance.

Parameters
closeable:CloseableChannel

the single central closeable channel

source:StreamSourceChannel

the stream source channel

sink:StreamSinkChannel

the stream sink channel

AssembledStreamChannelback to summary
public AssembledStreamChannel(final StreamSourceChannel source, final StreamSinkChannel sink)

Construct a new instance.

Parameters
source:StreamSourceChannel

the stream source channel

sink:StreamSinkChannel

the stream sink 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
awaitWritableback to summary
public void awaitWritable() throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Doc from org.xnio.channels.SuspendableWriteChannel.awaitWritable.

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

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

Implements org.xnio.channels.SuspendableWriteChannel.awaitWritable.

Doc from org.xnio.channels.SuspendableWriteChannel.awaitWritable.

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.

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 org.xnio.channels.CloseableChannel.close, org.xnio.channels.SuspendableWriteChannel.close, java.nio.channels.Channel.close.

Doc from org.xnio.channels.CloseableChannel.close.

Close this channel. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.

Exceptions
IOException:
if the close failed
flushback to summary
public boolean flush() throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.flush.

Doc from org.xnio.channels.SuspendableWriteChannel.flush.

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 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.

Returns:boolean

true if the message was flushed, or false if the result would block

Exceptions
IOException:
if an I/O error occurs
getCloseSetterback to summary
public ChannelListener.Setter<? extends AssembledStreamChannel> getCloseSetter()

Implements org.xnio.channels.StreamChannel.getCloseSetter.

Doc from org.xnio.channels.StreamChannel.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 AssembledStreamChannel>

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
getReadSetterback to summary
public ChannelListener.Setter<? extends AssembledStreamChannel> getReadSetter()

Implements org.xnio.channels.StreamChannel.getReadSetter.

Doc from org.xnio.channels.StreamChannel.getReadSetter.

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

Returns:ChannelListener.Setter<? extends AssembledStreamChannel>

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

getWriteSetterback to summary
public ChannelListener.Setter<? extends AssembledStreamChannel> getWriteSetter()

Implements org.xnio.channels.StreamChannel.getWriteSetter.

Doc from org.xnio.channels.StreamChannel.getWriteSetter.

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

Returns:ChannelListener.Setter<? extends AssembledStreamChannel>

Doc from org.xnio.channels.SuspendableWriteChannel.getWriteSetter.

the setter

getWriteThreadback to summary
public XnioExecutor getWriteThread()

Implements org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Doc from org.xnio.channels.SuspendableWriteChannel.getWriteThread.

Deprecated

Get the write thread for this channel.

Returns:XnioExecutor

the thread, or null if none is configured or available

Annotations
@Deprecated
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen, org.xnio.channels.SuspendableWriteChannel.isOpen.

Doc from org.xnio.channels.SuspendableWriteChannel.isOpen.

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.

Returns:boolean

true if the channel is open, false otherwise

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

isWriteResumedback to summary
public boolean isWriteResumed()

Implements org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Doc from org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Determine whether writes are resumed.

Returns:boolean

true if writes are resumed, false if writes 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.

resumeWritesback to summary
public void resumeWrites()

Implements org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Resume writes on this channel. The write listener will be called as soon as the channel becomes writable.

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
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
shutdownWritesback to summary
public void shutdownWrites() throws IOException

Implements org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.shutdownWrites.

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 flush() method; once this is done, if the read side of the channel was shut down, the channel will automatically close.

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.

suspendWritesback to summary
public void suspendWrites()

Implements org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.suspendWrites.

Suspend further write notifications on this channel.

transferFromback to summary
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Doc from org.xnio.channels.StreamSinkChannel.transferFrom.

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 java.io.InterruptedIOException; however, if this exception is thrown, the java.io.InterruptedIOException#bytesTransferred field is guaranteed to be 0.

Parameters
src:FileChannel

the file to read from

position:long

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

count:long

the number of bytes to be transferred

Returns:long

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

Exceptions
IOException:
if an I/O error occurs
transferFromback to summary
public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException

Implements org.xnio.channels.StreamSinkChannel.transferFrom.

Doc from org.xnio.channels.StreamSinkChannel.transferFrom.

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 java.io.InterruptedIOException; however, if this exception is thrown, the java.io.InterruptedIOException#bytesTransferred field is guaranteed to be 0.

Parameters
source:StreamSourceChannel

the source to read from

count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

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
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.

wakeupWritesback to summary
public void wakeupWrites()

Implements org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Doc from org.xnio.channels.SuspendableWriteChannel.wakeupWrites.

Resume writes on this channel, and force the write listener to be triggered even if the channel isn't actually writable.

writeback to summary
public int write(final 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.

Unless otherwise specified, 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.

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.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public long write(final ByteBuffer[] srcs, final int offset, final 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.

Unless otherwise specified, 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.

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.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

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:int

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

Returns:long

The number of bytes written, possibly zero

Exceptions
IOException:
If some other I/O error occurs
writeback to summary
public long write(final 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);
Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

Returns:long

The number of bytes written, possibly zero

Exceptions
IOException:
If some other I/O error occurs
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Doc from org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as 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.

Parameters
src:ByteBuffer

The data to write

Returns:int

The amount of data that was actually written.

Annotations
@Override
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Doc from org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as 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.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

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:int

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

Returns:long

The amount of data that was actually written

Annotations
@Override
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs) throws IOException

Implements org.xnio.channels.StreamSinkChannel.writeFinal.

Doc from org.xnio.channels.StreamSinkChannel.writeFinal.

Writes some data to the channel, with the same semantics as 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.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

Returns:long

The amount of data that was actually written

Annotations
@Override