Top Description Methods
org.xnio.channels

public Interface StreamSinkChannel

extends WritableByteChannel, GatheringByteChannel, SuspendableWriteChannel
Known Direct Subinterfaces
org.xnio.channels.StreamChannel
Known Direct Implementers
org.xnio.channels.FixedLengthStreamSinkChannel, org.xnio.conduits.ConduitStreamSinkChannel, org.xnio.channels.NullStreamSinkChannel, org.xnio.channels.SplitStreamSinkChannel
Imports
java.nio.ByteBuffer, java.nio.channels.WritableByteChannel, .GatheringByteChannel, .FileChannel, java.io.IOException, org.xnio.ChannelListener

A stream sink channel. This type of channel is a writable destination for bytes. While all channel types are thread-safe, writing a stream from more than one thread concurrently will cause data corruption and may be disallowed at the option of the implementation.

Method Summary

Modifier and TypeMethod and Description
public ChannelListener.Setter<? extends StreamSinkChannel>
getCloseSetter()

Redeclares org.xnio.channels.SuspendableWriteChannel.getCloseSetter.

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

public ChannelListener.Setter<? extends StreamSinkChannel>
getWriteSetter()

Redeclares org.xnio.channels.SuspendableWriteChannel.getWriteSetter.

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

public long

Returns:

the number of bytes (possibly 0) that were actually transferred
transferFrom
(FileChannel
the file to read from
src
,
long
the position within the file from which the transfer is to begin
position
,
long
the number of bytes to be transferred
count
)

Transfer bytes into this channel from the given file.

public long

Returns:

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached
transferFrom
(StreamSourceChannel
the source to read from
source
,
long
the number of bytes to be transferred
count
,
ByteBuffer
the buffer to copy through.
throughBuffer
)

Transfers bytes from the given channel source.

public int

Returns:

The amount of data that was actually written.
writeFinal
(ByteBuffer
The data to write
src
)

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

public long

Returns:

The amount of data that was actually written
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
)

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

public long

Returns:

The amount of data that was actually written
writeFinal
(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
)

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

Inherited from java.nio.channels.GatheringByteChannel:
writewrite
Inherited from java.nio.channels.WritableByteChannel:
write
Inherited from org.xnio.channels.SuspendableWriteChannel:
awaitWritableawaitWritablecloseflushgetWriteThreadisOpenisWriteResumedresumeWritesshutdownWritessuspendWriteswakeupWrites

Method Detail

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

Redeclares org.xnio.channels.SuspendableWriteChannel.getCloseSetter.

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

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

the setter

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

Redeclares org.xnio.channels.SuspendableWriteChannel.getWriteSetter.

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

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

Returns:ChannelListener.Setter<? extends StreamSinkChannel>

the setter

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

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(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException

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
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

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.

See Also
WritableByteChannel#write(java.nio.ByteBuffer), SuspendableWriteChannel#shutdownWrites()
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException

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

See Also
GatheringByteChannel#write(java.nio.ByteBuffer[], int, int), SuspendableWriteChannel#shutdownWrites()
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs) throws IOException

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

See Also
GatheringByteChannel#write(java.nio.ByteBuffer[]), SuspendableWriteChannel#shutdownWrites()