Package org.xnio.channels
Class EmptyStreamSourceChannel
java.lang.Object
org.xnio.channels.EmptyStreamSourceChannel
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,InterruptibleChannel,ReadableByteChannel,ScatteringByteChannel,CloseableChannel,CloseListenerSettable<EmptyStreamSourceChannel>,Configurable,ReadListenerSettable<EmptyStreamSourceChannel>,StreamSourceChannel,SuspendableReadChannel
public class EmptyStreamSourceChannel
extends Object
implements StreamSourceChannel, ReadListenerSettable<EmptyStreamSourceChannel>, CloseListenerSettable<EmptyStreamSourceChannel>
A stream source channel which is always empty.
- Author:
- David M. Lloyd
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.xnio.channels.CloseListenerSettable
CloseListenerSettable.Setter<C extends Channel>Nested classes/interfaces inherited from interface org.xnio.channels.ReadListenerSettable
ReadListenerSettable.Setter<C extends Channel> -
Field Summary
Fields inherited from interface org.xnio.channels.Configurable
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBlock until this channel becomes readable again.voidawaitReadable(long time, TimeUnit timeUnit) Block until this channel becomes readable again, or until the timeout expires.voidclose()Close this channel.ChannelListener<? super EmptyStreamSourceChannel>Get the close listener.ChannelListener.Setter<? extends EmptyStreamSourceChannel>Get the setter which can be used to change the close listener for this channel.Get the I/O thread associated with this channel.<T> TGet the value of a channel option.ChannelListener<? super EmptyStreamSourceChannel>Get the read listener.ChannelListener.Setter<? extends EmptyStreamSourceChannel>Get the setter which can be used to change the read listener for this channel.Deprecated.Get the worker for this channel.booleanisOpen()booleanDetermine whether reads are resumed.intread(ByteBuffer dst) longread(ByteBuffer[] dsts) longread(ByteBuffer[] dsts, int offset, int length) voidResume reads on this channel.voidsetCloseListener(ChannelListener<? super EmptyStreamSourceChannel> closeListener) Set the close listener.<T> TSet an option for this channel.voidsetReadListener(ChannelListener<? super EmptyStreamSourceChannel> readListener) Set the read listener.voidPlaces this readable channel at "end of stream".booleansupportsOption(Option<?> option) Determine whether an option is supported on this channel.voidSuspend further read notifications on this channel.longtransferTo(long position, long count, FileChannel target) Transfers bytes into the given file from this channel.longtransferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel target) Transfers bytes into the given channel target.voidResume readson this channel, and force the read listener to be triggered even if the channel isn't actually readable.
-
Constructor Details
-
EmptyStreamSourceChannel
Construct a new instance.- Parameters:
thread- the XNIO read thread to use
-
-
Method Details
-
transferTo
Description copied from interface:StreamSourceChannelTransfers bytes into the given file from this channel. Using this method in preference toFileChannel.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, theInterruptedIOException.bytesTransferredfield is guaranteed to be 0.- Specified by:
transferToin interfaceStreamSourceChannel- Parameters:
position- the position within the file from which the transfer is to begincount- the number of bytes to be transferredtarget- the file to write to- Returns:
- the number of bytes (possibly 0) that were actually transferred
- Throws:
IOException- if an I/O error occurs
-
transferTo
public long transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel target) throws IOException Description copied from interface:StreamSourceChannelTransfers 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 thethroughBufferparameter's buffer space. On entry,throughBufferwill 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 thancount, then the remaining data inthroughBuffermay contain data read from this channel which must be written totargetto 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, theInterruptedIOException.bytesTransferredfield is guaranteed to be 0. Note that the return value is the amount of data that was actually transferred to theStreamSinkChannel. 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 inthroughBuffer.- Specified by:
transferToin interfaceStreamSourceChannel- Parameters:
count- the number of bytes to be transferredthroughBuffer- the buffer to copy through.target- the destination to write to- Returns:
- the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached
- Throws:
IOException- if an I/O error occurs
-
setReadListener
Description copied from interface:ReadListenerSettableSet the read listener.- Specified by:
setReadListenerin interfaceReadListenerSettable<EmptyStreamSourceChannel>- Parameters:
readListener- the read listener
-
getReadListener
Description copied from interface:ReadListenerSettableGet the read listener.- Specified by:
getReadListenerin interfaceReadListenerSettable<EmptyStreamSourceChannel>- Returns:
- the read listener
-
setCloseListener
Description copied from interface:CloseListenerSettableSet the close listener.- Specified by:
setCloseListenerin interfaceCloseListenerSettable<EmptyStreamSourceChannel>- Parameters:
closeListener- the close listener
-
getCloseListener
Description copied from interface:CloseListenerSettableGet the close listener.- Specified by:
getCloseListenerin interfaceCloseListenerSettable<EmptyStreamSourceChannel>- Returns:
- the close listener
-
getReadSetter
Description copied from interface:StreamSourceChannelGet the setter which can be used to change the read listener for this channel.- Specified by:
getReadSetterin interfaceStreamSourceChannel- Specified by:
getReadSetterin interfaceSuspendableReadChannel- Returns:
- the setter
-
getCloseSetter
Description copied from interface:StreamSourceChannelGet 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.- Specified by:
getCloseSetterin interfaceCloseableChannel- Specified by:
getCloseSetterin interfaceStreamSourceChannel- Specified by:
getCloseSetterin interfaceSuspendableReadChannel- Returns:
- the setter
-
read
- Specified by:
readin interfaceScatteringByteChannel- Throws:
IOException
-
read
- Specified by:
readin interfaceScatteringByteChannel- Throws:
IOException
-
read
- Specified by:
readin interfaceReadableByteChannel- Throws:
IOException
-
suspendReads
public void suspendReads()Description copied from interface:SuspendableReadChannelSuspend further read notifications on this channel.- Specified by:
suspendReadsin interfaceSuspendableReadChannel
-
resumeReads
public void resumeReads()Description copied from interface:SuspendableReadChannelResume reads on this channel. The read listener will be called as soon as there is data available to be read.- Specified by:
resumeReadsin interfaceSuspendableReadChannel
-
isReadResumed
public boolean isReadResumed()Description copied from interface:SuspendableReadChannelDetermine whether reads are resumed.- Specified by:
isReadResumedin interfaceSuspendableReadChannel- Returns:
trueif reads are resumed,falseif reads are suspended
-
wakeupReads
public void wakeupReads()Description copied from interface:SuspendableReadChannelResume readson this channel, and force the read listener to be triggered even if the channel isn't actually readable.- Specified by:
wakeupReadsin interfaceSuspendableReadChannel
-
shutdownReads
Description copied from interface:SuspendableReadChannelPlaces this readable channel at "end of stream". Further reads will result in EOF. Shutting down all directions of a channel will causeCloseableChannel.close()to be called automatically.- Specified by:
shutdownReadsin interfaceSuspendableReadChannel- Throws:
IOException- if an I/O error occurs
-
awaitReadable
Description copied from interface:SuspendableReadChannelBlock until this channel becomes readable again. This method may return spuriously before the channel becomes readable.- Specified by:
awaitReadablein interfaceSuspendableReadChannel- Throws:
InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException- if an I/O error occurs
-
awaitReadable
Description copied from interface:SuspendableReadChannelBlock 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.- Specified by:
awaitReadablein interfaceSuspendableReadChannel- Parameters:
time- the time to waittimeUnit- the time unit- Throws:
InterruptedIOException- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException- if an I/O error occurs
-
getReadThread
Deprecated.Description copied from interface:SuspendableReadChannelGet the read thread for this channel.- Specified by:
getReadThreadin interfaceSuspendableReadChannel- Returns:
- the thread, or
nullif none is configured or available
-
getIoThread
Description copied from interface:CloseableChannelGet the I/O thread associated with this channel.- Specified by:
getIoThreadin interfaceCloseableChannel- Returns:
- the I/O thread associated with this channel
-
getWorker
Description copied from interface:CloseableChannelGet the worker for this channel.- Specified by:
getWorkerin interfaceCloseableChannel- Returns:
- the worker
-
isOpen
public boolean isOpen() -
close
Description copied from interface:CloseableChannelClose this channel. When a channel is closed, its close listener is invoked. Invoking this method more than once has no additional effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCloseableChannel- Specified by:
closein interfaceInterruptibleChannel- Throws:
IOException- if the close failed
-
supportsOption
Description copied from interface:ConfigurableDetermine whether an option is supported on this channel.- Specified by:
supportsOptionin interfaceConfigurable- Parameters:
option- the option- Returns:
trueif it is supported
-
getOption
Description copied from interface:ConfigurableGet the value of a channel option.- Specified by:
getOptionin interfaceConfigurable- Type Parameters:
T- the type of the option value- Parameters:
option- the option to get- Returns:
- the value of the option, or
nullif it is not set - Throws:
IOException- if an I/O error occurred when reading the option
-
setOption
Description copied from interface:ConfigurableSet an option for this channel. Unsupported options are ignored.- Specified by:
setOptionin interfaceConfigurable- Type Parameters:
T- the type of the option value- Parameters:
option- the option to setvalue- the value of the option to set- Returns:
- the previous option value, if any
- Throws:
IllegalArgumentException- if the value is not acceptable for this optionIOException- if an I/O error occurred when modifying the option
-