public class AssembledStreamChannel extends java.lang.Object implements StreamChannel
EMPTY| Constructor and Description |
|---|
AssembledStreamChannel(CloseableChannel closeable,
StreamSourceChannel source,
StreamSinkChannel sink)
Construct a new instance.
|
AssembledStreamChannel(StreamSourceChannel source,
StreamSinkChannel sink)
Construct a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
awaitReadable()
Block until this channel becomes readable again.
|
void |
awaitReadable(long time,
java.util.concurrent.TimeUnit timeUnit)
Block until this channel becomes readable again, or until the timeout expires.
|
void |
awaitWritable()
Block until this channel becomes writable again.
|
void |
awaitWritable(long time,
java.util.concurrent.TimeUnit timeUnit)
Block until this channel becomes writable again, or until the timeout expires.
|
void |
close()
Close this channel.
|
boolean |
flush()
Flush any waiting partial send or write.
|
ChannelListener.Setter<? extends AssembledStreamChannel> |
getCloseSetter()
Get the setter which can be used to change the close listener for this channel.
|
XnioIoThread |
getIoThread()
Get the I/O thread associated with this channel.
|
<T> T |
getOption(Option<T> option)
Get the value of a channel option.
|
ChannelListener.Setter<? extends AssembledStreamChannel> |
getReadSetter()
Get the setter which can be used to change the read listener for this channel.
|
XnioExecutor |
getReadThread()
Deprecated.
|
XnioWorker |
getWorker()
Get the worker for this channel.
|
ChannelListener.Setter<? extends AssembledStreamChannel> |
getWriteSetter()
Get the setter which can be used to change the write listener for this channel.
|
XnioExecutor |
getWriteThread()
Deprecated.
|
boolean |
isOpen()
Determine whether this channel is open.
|
boolean |
isReadResumed()
Determine whether reads are resumed.
|
boolean |
isWriteResumed()
Determine whether writes are resumed.
|
int |
read(java.nio.ByteBuffer dst) |
long |
read(java.nio.ByteBuffer[] dsts) |
long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length) |
void |
resumeReads()
Resume reads on this channel.
|
void |
resumeWrites()
Resume writes on this channel.
|
<T> T |
setOption(Option<T> option,
T value)
Set an option for this channel.
|
void |
shutdownReads()
Places this readable channel at "end of stream".
|
void |
shutdownWrites()
Indicate that writing is complete for this channel.
|
boolean |
supportsOption(Option<?> option)
Determine whether an option is supported on this channel.
|
void |
suspendReads()
Suspend further read notifications on this channel.
|
void |
suspendWrites()
Suspend further write notifications on this channel.
|
long |
transferFrom(FileChannel src,
long position,
long count)
Transfer bytes into this channel from the given file.
|
long |
transferFrom(StreamSourceChannel source,
long count,
java.nio.ByteBuffer throughBuffer)
Transfers bytes from the given channel source.
|
long |
transferTo(long count,
java.nio.ByteBuffer throughBuffer,
StreamSinkChannel target)
Transfers bytes into the given channel target.
|
long |
transferTo(long position,
long count,
FileChannel target)
Transfers bytes into the given file from this channel.
|
void |
wakeupReads()
Resume reads on this channel, and force the read listener to be triggered even if the
channel isn't actually readable. |
void |
wakeupWrites()
Resume writes on this channel, and force the write listener to be triggered even if the
channel isn't actually writable. |
int |
write(java.nio.ByteBuffer src) |
long |
write(java.nio.ByteBuffer[] srcs) |
long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length) |
int |
writeFinal(java.nio.ByteBuffer src)
Writes some data to the channel, with the same semantics as
WritableByteChannel.write(java.nio.ByteBuffer). |
long |
writeFinal(java.nio.ByteBuffer[] srcs)
Writes some data to the channel, with the same semantics as
GatheringByteChannel.write(java.nio.ByteBuffer[]). |
long |
writeFinal(java.nio.ByteBuffer[] srcs,
int offset,
int length)
Writes some data to the channel, with the same semantics as
GatheringByteChannel.write(java.nio.ByteBuffer[], int, int). |
public AssembledStreamChannel(CloseableChannel closeable, StreamSourceChannel source, StreamSinkChannel sink)
closeable - the single central closeable channelsource - the stream source channelsink - the stream sink channelpublic AssembledStreamChannel(StreamSourceChannel source, StreamSinkChannel sink)
source - the stream source channelsink - the stream sink channelpublic ChannelListener.Setter<? extends AssembledStreamChannel> getReadSetter()
StreamChannelgetReadSetter in interface StreamChannelgetReadSetter in interface StreamSourceChannelgetReadSetter in interface SuspendableChannelgetReadSetter in interface SuspendableReadChannelpublic void suspendReads()
SuspendableReadChannelsuspendReads in interface SuspendableReadChannelpublic void resumeReads()
SuspendableReadChannelresumeReads in interface SuspendableReadChannelpublic boolean isReadResumed()
SuspendableReadChannelisReadResumed in interface SuspendableReadChanneltrue if reads are resumed, false if reads are suspendedpublic void wakeupReads()
SuspendableReadChannelResume reads on this channel, and force the read listener to be triggered even if the
channel isn't actually readable.wakeupReads in interface SuspendableReadChannelpublic void shutdownReads()
throws java.io.IOException
SuspendableReadChannelCloseableChannel.close() to be called automatically.shutdownReads in interface SuspendableReadChanneljava.io.IOException - if an I/O error occurspublic void awaitReadable()
throws java.io.IOException
SuspendableReadChannelawaitReadable in interface SuspendableReadChanneljava.io.InterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException - if an I/O error occurspublic void awaitReadable(long time,
java.util.concurrent.TimeUnit timeUnit)
throws java.io.IOException
SuspendableReadChannelawaitReadable in interface SuspendableReadChanneltime - the time to waittimeUnit - the time unitjava.io.InterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException - if an I/O error occurs@Deprecated public XnioExecutor getReadThread()
SuspendableReadChannelgetReadThread in interface SuspendableReadChannelnull if none is configured or availablepublic XnioIoThread getIoThread()
CloseableChannelgetIoThread in interface CloseableChannelpublic int read(java.nio.ByteBuffer dst)
throws java.io.IOException
read in interface java.nio.channels.ReadableByteChanneljava.io.IOExceptionpublic long read(java.nio.ByteBuffer[] dsts,
int offset,
int length)
throws java.io.IOException
read in interface java.nio.channels.ScatteringByteChanneljava.io.IOExceptionpublic long read(java.nio.ByteBuffer[] dsts)
throws java.io.IOException
read in interface java.nio.channels.ScatteringByteChanneljava.io.IOExceptionpublic long transferTo(long position,
long count,
FileChannel target)
throws java.io.IOException
StreamSourceChannelFileChannel.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 InterruptedIOException;
however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is
guaranteed to be 0.
transferTo in interface StreamSourceChannelposition - the position within the file from which the transfer is to begincount - the number of bytes to be transferredtarget - the file to write tojava.io.IOException - if an I/O error occurspublic long transferTo(long count,
java.nio.ByteBuffer throughBuffer,
StreamSinkChannel target)
throws java.io.IOException
StreamSourceChannelthroughBuffer 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 InterruptedIOException;
however, if this exception is thrown, the 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.
transferTo in interface StreamSourceChannelcount - the number of bytes to be transferredthroughBuffer - the buffer to copy through.target - the destination to write tojava.io.IOException - if an I/O error occurspublic long transferFrom(FileChannel src, long position, long count) throws java.io.IOException
StreamSinkChannelFileChannel.transferTo(long, long, WritableByteChannel)
may provide a performance advantage on some platforms.
If the current thread is interrupted when this method is called, it may throw a InterruptedIOException;
however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is
guaranteed to be 0.
transferFrom in interface StreamSinkChannelsrc - the file to read fromposition - the position within the file from which the transfer is to begincount - the number of bytes to be transferredjava.io.IOException - if an I/O error occurspublic long transferFrom(StreamSourceChannel source, long count, java.nio.ByteBuffer throughBuffer) throws java.io.IOException
StreamSinkChannelthroughBuffer parameter's buffer
space. On entry, throughBuffer will be cleared. On exit, the buffer will be
flipped for emptying, and may be empty or may contain data. If this method returns a value less than
count, then the remaining data in throughBuffer may contain data read from source which must
be written to this channel to complete the operation. Note that using a direct buffer may provide an
intermediate performance gain on platforms without zero-copy facilities.
If the current thread is interrupted when this method is called, it may throw a InterruptedIOException;
however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is
guaranteed to be 0.
transferFrom in interface StreamSinkChannelsource - the source to read fromcount - the number of bytes to be transferredthroughBuffer - the buffer to copy through.java.io.IOException - if an I/O error occurspublic ChannelListener.Setter<? extends AssembledStreamChannel> getWriteSetter()
StreamChannelgetWriteSetter in interface StreamChannelgetWriteSetter in interface StreamSinkChannelgetWriteSetter in interface SuspendableChannelgetWriteSetter in interface SuspendableWriteChannelpublic int write(java.nio.ByteBuffer src)
throws java.io.IOException
write in interface java.nio.channels.WritableByteChanneljava.io.IOExceptionpublic long write(java.nio.ByteBuffer[] srcs,
int offset,
int length)
throws java.io.IOException
write in interface java.nio.channels.GatheringByteChanneljava.io.IOExceptionpublic long write(java.nio.ByteBuffer[] srcs)
throws java.io.IOException
write in interface java.nio.channels.GatheringByteChanneljava.io.IOExceptionpublic void suspendWrites()
SuspendableWriteChannelsuspendWrites in interface SuspendableWriteChannelpublic void resumeWrites()
SuspendableWriteChannelresumeWrites in interface SuspendableWriteChannelpublic boolean isWriteResumed()
SuspendableWriteChannelisWriteResumed in interface SuspendableWriteChanneltrue if writes are resumed, false if writes are suspendedpublic void wakeupWrites()
SuspendableWriteChannelResume writes on this channel, and force the write listener to be triggered even if the
channel isn't actually writable.wakeupWrites in interface SuspendableWriteChannelpublic void shutdownWrites()
throws java.io.IOException
SuspendableWriteChannelSuspendableWriteChannel.flush() method; once this is done, if the read side of the channel was shut down, the channel will
automatically close.shutdownWrites in interface SuspendableWriteChanneljava.io.IOException - if an I/O error occurspublic void awaitWritable()
throws java.io.IOException
SuspendableWriteChannelawaitWritable in interface SuspendableWriteChanneljava.io.InterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException - if an I/O error occurspublic void awaitWritable(long time,
java.util.concurrent.TimeUnit timeUnit)
throws java.io.IOException
SuspendableWriteChannelawaitWritable in interface SuspendableWriteChanneltime - the time to waittimeUnit - the time unitjava.io.InterruptedIOException - if the operation is interrupted; the thread's interrupt flag will be set as welljava.io.IOException - if an I/O error occurs@Deprecated public XnioExecutor getWriteThread()
SuspendableWriteChannelgetWriteThread in interface SuspendableWriteChannelnull if none is configured or availablepublic boolean flush()
throws java.io.IOException
SuspendableWriteChanneltrue. If there is data to flush which cannot be immediately written, this method
will return false. If this method returns true after SuspendableWriteChannel.shutdownWrites() was called on
this channel, the write listener will no longer be invoked on this channel. If this is case and additionally
this is a write-only channel or the read side was previously shut down, then the channel will
automatically be closed.flush in interface SuspendableWriteChanneltrue if the message was flushed, or false if the result would blockjava.io.IOException - if an I/O error occurspublic ChannelListener.Setter<? extends AssembledStreamChannel> getCloseSetter()
StreamChannelgetCloseSetter in interface CloseableChannelgetCloseSetter in interface StreamChannelgetCloseSetter in interface StreamSinkChannelgetCloseSetter in interface StreamSourceChannelgetCloseSetter in interface SuspendableChannelgetCloseSetter in interface SuspendableReadChannelgetCloseSetter in interface SuspendableWriteChannelpublic int writeFinal(java.nio.ByteBuffer src)
throws java.io.IOException
StreamSinkChannelWritableByteChannel.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.writeFinal in interface StreamSinkChannelsrc - The data to writejava.io.IOExceptionWritableByteChannel.write(java.nio.ByteBuffer),
SuspendableWriteChannel.shutdownWrites()public long writeFinal(java.nio.ByteBuffer[] srcs,
int offset,
int length)
throws java.io.IOException
StreamSinkChannelGatheringByteChannel.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.writeFinal in interface StreamSinkChannelsrcs - The buffers from which bytes are to be retrievedoffset - 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.lengthlength - The maximum number of buffers to be accessed; must be
non-negative and no larger than
srcs.length - offsetjava.io.IOExceptionGatheringByteChannel.write(java.nio.ByteBuffer[], int, int),
SuspendableWriteChannel.shutdownWrites()public long writeFinal(java.nio.ByteBuffer[] srcs)
throws java.io.IOException
StreamSinkChannelGatheringByteChannel.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.writeFinal in interface StreamSinkChannelsrcs - The buffers from which bytes are to be retrievedjava.io.IOExceptionGatheringByteChannel.write(java.nio.ByteBuffer[]),
SuspendableWriteChannel.shutdownWrites()public XnioWorker getWorker()
CloseableChannelgetWorker in interface CloseableChannelpublic void close()
throws java.io.IOException
CloseableChannelclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in interface java.nio.channels.InterruptibleChannelclose in interface CloseableChannelclose in interface SuspendableWriteChanneljava.io.IOException - if the close failedpublic boolean isOpen()
SuspendableWriteChannelfalse if all directions are shut down,
even if there is unflushed write data pending.isOpen in interface java.nio.channels.ChannelisOpen in interface SuspendableWriteChanneltrue if the channel is open, false otherwisepublic boolean supportsOption(Option<?> option)
ConfigurablesupportsOption in interface Configurableoption - the optiontrue if it is supportedpublic <T> T getOption(Option<T> option) throws java.io.IOException
ConfigurablegetOption in interface ConfigurableT - the type of the option valueoption - the option to getnull if it is not setjava.io.IOException - if an I/O error occurred when reading the optionpublic <T> T setOption(Option<T> option, T value) throws java.lang.IllegalArgumentException, java.io.IOException
ConfigurablesetOption in interface ConfigurableT - the type of the option valueoption - the option to setvalue - the value of the option to setjava.lang.IllegalArgumentException - if the value is not acceptable for this optionjava.io.IOException - if an I/O error occurred when modifying the optionCopyright © 2016 JBoss, a division of Red Hat, Inc.