Top Description Fields Constructors Methods
org.xnio.channels

public final Class FixedLengthStreamSinkChannel

extends Object
implements StreamSinkChannel, ProtectedWrappedChannel<StreamSinkChannel>, WriteListenerSettable<FixedLengthStreamSinkChannel>, CloseListenerSettable<FixedLengthStreamSinkChannel>
Class Inheritance
All Implemented Interfaces
org.xnio.channels.CloseListenerSettable, org.xnio.channels.WriteListenerSettable, org.xnio.channels.ProtectedWrappedChannel, org.xnio.channels.StreamSinkChannel, org.xnio.channels.SuspendableWriteChannel, 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.GatheringByteChannel, java.nio.channels.WritableByteChannel
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, .FileChannel, java.util.concurrent.TimeUnit, org.xnio.ChannelListener, .ChannelListeners, .Option, .XnioExecutor, .XnioIoThread, .XnioWorker

A channel which writes a fixed amount of data. A listener is called once the data has been written.
Author
David M. Lloyd

Field Summary

Modifier and TypeField and Description
private ChannelListener<? super FixedLengthStreamSinkChannel>
private long
private final StreamSinkChannel
private final ChannelListener<? super FixedLengthStreamSinkChannel>
private static final int
private static final int
private static final int
private static final int
private final Object
private int
private ChannelListener<? super FixedLengthStreamSinkChannel>

Constructor Summary

AccessConstructor and Description
public
FixedLengthStreamSinkChannel(final StreamSinkChannel
the delegate channel
delegate
,
final long
the content length
contentLength
,
final boolean
true if this instance should pass configuration to the delegate
configurable
,
final boolean
true if this instance should pass close to the delegate
propagateClose
,
final ChannelListener<? super FixedLengthStreamSinkChannel>
the listener to call when the channel is closed or the length is reached
finishListener
,
final Object
the guard object to use
guard
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
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.

private void
private void
public void
private long
doWrite(ByteBuffer[] srcs, int offset, int length, final boolean writeFinal)

private int
doWrite(ByteBuffer src, boolean finalWrite)

public boolean
flush()

Implements org.xnio.channels.SuspendableWriteChannel.flush.

Flush any waiting partial send or write.

public StreamSinkChannel
getChannel(final Object
the guard object
guard
)

Implements org.xnio.channels.ProtectedWrappedChannel.getChannel.

Get the channel which is wrapped by this object, or null if the guard is invalid.

public ChannelListener<? super FixedLengthStreamSinkChannel>
public ChannelListener.Setter<FixedLengthStreamSinkChannel>
getCloseSetter()

Implements org.xnio.channels.StreamSinkChannel.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 long

Returns:

the number of remaining bytes
getRemaining
()

Get the number of remaining bytes in this fixed length channel.

public XnioWorker
getWorker()

Implements org.xnio.channels.CloseableChannel.getWorker.

Get the worker for this channel.

public ChannelListener<? super FixedLengthStreamSinkChannel>
public ChannelListener.Setter<FixedLengthStreamSinkChannel>
getWriteSetter()

Implements org.xnio.channels.StreamSinkChannel.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
isWriteResumed()

Implements org.xnio.channels.SuspendableWriteChannel.isWriteResumed.

Determine whether writes are resumed.

public void
resumeWrites()

Implements org.xnio.channels.SuspendableWriteChannel.resumeWrites.

Resume writes on this channel.

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

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
setWriteListener(final ChannelListener<? super FixedLengthStreamSinkChannel>
the write listener
listener
)

Implements org.xnio.channels.WriteListenerSettable.setWriteListener.

Set the write listener.

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

private int
write(final ByteBuffer src, final boolean finalWrite)

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

private long
write(final ByteBuffer[] srcs, final int offset, final int length, boolean writeFinal)

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

closeListenerback to summary
private ChannelListener<? super FixedLengthStreamSinkChannel> closeListener
countback to summary
private long count
delegateback to summary
private final StreamSinkChannel delegate
finishListenerback to summary
private final ChannelListener<? super FixedLengthStreamSinkChannel> finishListener
FLAG_CLOSE_COMPLETEback to summary
private static final int FLAG_CLOSE_COMPLETE
FLAG_CLOSE_REQUESTEDback to summary
private static final int FLAG_CLOSE_REQUESTED
FLAG_CONFIGURABLEback to summary
private static final int FLAG_CONFIGURABLE
FLAG_PASS_CLOSEback to summary
private static final int FLAG_PASS_CLOSE
guardback to summary
private final Object guard
stateback to summary
private int state
writeListenerback to summary
private ChannelListener<? super FixedLengthStreamSinkChannel> writeListener

Constructor Detail

FixedLengthStreamSinkChannelback to summary
public FixedLengthStreamSinkChannel(final StreamSinkChannel delegate, final long contentLength, final boolean configurable, final boolean propagateClose, final ChannelListener<? super FixedLengthStreamSinkChannel> finishListener, final Object guard)

Construct a new instance.

Parameters
delegate:StreamSinkChannel

the delegate channel

contentLength:long

the content length

configurable:boolean

true if this instance should pass configuration to the delegate

propagateClose:boolean

true if this instance should pass close to the delegate

finishListener:ChannelListener<? super FixedLengthStreamSinkChannel>

the listener to call when the channel is closed or the length is reached

guard:Object

the guard object to use

Method Detail

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
callClosedback to summary
private void callClosed()
callFinishback to summary
private void callFinish()
closeback to summary
public void close() throws IOException

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

Doc from org.xnio.channels.SuspendableWriteChannel.close.

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.

Exceptions
IOException:
if the close failed
doWriteback to summary
private long doWrite(ByteBuffer[] srcs, int offset, int length, final boolean writeFinal) throws IOException
doWriteback to summary
private int doWrite(ByteBuffer src, boolean finalWrite) throws IOException
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
getChannelback to summary
public StreamSinkChannel getChannel(final Object guard)

Implements org.xnio.channels.ProtectedWrappedChannel.getChannel.

Doc from org.xnio.channels.ProtectedWrappedChannel.getChannel.

Get the channel which is wrapped by this object, or null if the guard is invalid.

Parameters
guard:Object

the guard object

Returns:StreamSinkChannel

the wrapped channel

getCloseListenerback to summary
public ChannelListener<? super FixedLengthStreamSinkChannel> getCloseListener()

Implements org.xnio.channels.CloseListenerSettable.getCloseListener.

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

Get the close listener.

Returns:ChannelListener<? super FixedLengthStreamSinkChannel>

the close listener

getCloseSetterback to summary
public ChannelListener.Setter<FixedLengthStreamSinkChannel> getCloseSetter()

Implements org.xnio.channels.StreamSinkChannel.getCloseSetter.

Doc from org.xnio.channels.StreamSinkChannel.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<FixedLengthStreamSinkChannel>

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
getRemainingback to summary
public long getRemaining()

Get the number of remaining bytes in this fixed length channel.

Returns:long

the number of remaining bytes

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

getWriteListenerback to summary
public ChannelListener<? super FixedLengthStreamSinkChannel> getWriteListener()

Implements org.xnio.channels.WriteListenerSettable.getWriteListener.

Doc from org.xnio.channels.WriteListenerSettable.getWriteListener.

Get the write listener.

Returns:ChannelListener<? super FixedLengthStreamSinkChannel>

the write listener

getWriteSetterback to summary
public ChannelListener.Setter<FixedLengthStreamSinkChannel> getWriteSetter()

Implements org.xnio.channels.StreamSinkChannel.getWriteSetter.

Doc from org.xnio.channels.StreamSinkChannel.getWriteSetter.

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

Returns:ChannelListener.Setter<FixedLengthStreamSinkChannel>

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

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

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.

setCloseListenerback to summary
public void setCloseListener(final ChannelListener<? super FixedLengthStreamSinkChannel> listener)

Implements org.xnio.channels.CloseListenerSettable.setCloseListener.

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

Set the close listener.

Parameters
listener:ChannelListener<? super FixedLengthStreamSinkChannel>

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
setWriteListenerback to summary
public void setWriteListener(final ChannelListener<? super FixedLengthStreamSinkChannel> listener)

Implements org.xnio.channels.WriteListenerSettable.setWriteListener.

Doc from org.xnio.channels.WriteListenerSettable.setWriteListener.

Set the write listener.

Parameters
listener:ChannelListener<? super FixedLengthStreamSinkChannel>

the write listener

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

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

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeback to summary
private int write(final ByteBuffer src, final boolean finalWrite) throws IOException
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
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
private long write(final ByteBuffer[] srcs, final int offset, final int length, boolean writeFinal) throws IOException
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