public final class FixedLengthStreamSourceChannel extends java.lang.Object implements StreamSourceChannel, ProtectedWrappedChannel<StreamSourceChannel>, ReadListenerSettable<FixedLengthStreamSourceChannel>, CloseListenerSettable<FixedLengthStreamSourceChannel>
getRemaining()
to see if more bytes were pending when the channel was
closed.ReadListenerSettable.Setter<C extends java.nio.channels.Channel>
CloseListenerSettable.Setter<C extends java.nio.channels.Channel>
EMPTY
Constructor and Description |
---|
FixedLengthStreamSourceChannel(StreamSourceChannel delegate,
long contentLength,
boolean configurable,
boolean propagateClose,
ChannelListener<? super FixedLengthStreamSourceChannel> finishListener,
java.lang.Object guard)
Construct a new instance.
|
FixedLengthStreamSourceChannel(StreamSourceChannel delegate,
long contentLength,
boolean configurable,
ChannelListener<? super FixedLengthStreamSourceChannel> finishListener,
java.lang.Object guard)
Construct a new instance.
|
FixedLengthStreamSourceChannel(StreamSourceChannel delegate,
long contentLength,
ChannelListener<? super FixedLengthStreamSourceChannel> finishListener,
java.lang.Object guard)
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 |
close()
Close this channel.
|
StreamSourceChannel |
getChannel(java.lang.Object guard)
Get the channel which is wrapped by this object, or
null if the guard is invalid. |
ChannelListener<? super FixedLengthStreamSourceChannel> |
getCloseListener()
Get the close listener.
|
ChannelListener.Setter<FixedLengthStreamSourceChannel> |
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<? super FixedLengthStreamSourceChannel> |
getReadListener()
Get the read listener.
|
ChannelListener.Setter<FixedLengthStreamSourceChannel> |
getReadSetter()
Get the setter which can be used to change the read listener for this channel.
|
XnioExecutor |
getReadThread()
Deprecated.
|
long |
getRemaining()
Get the number of remaining bytes.
|
XnioWorker |
getWorker()
Get the worker for this channel.
|
boolean |
isOpen() |
boolean |
isReadResumed()
Determine whether reads 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 |
setCloseListener(ChannelListener<? super FixedLengthStreamSourceChannel> closeListener)
Set the close listener.
|
<T> T |
setOption(Option<T> option,
T value)
Set an option for this channel.
|
void |
setReadListener(ChannelListener<? super FixedLengthStreamSourceChannel> readListener)
Set the read listener.
|
void |
shutdownReads()
Places this readable channel at "end of stream".
|
boolean |
supportsOption(Option<?> option)
Determine whether an option is supported on this channel.
|
void |
suspendReads()
Suspend further read notifications on this channel.
|
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. |
public FixedLengthStreamSourceChannel(StreamSourceChannel delegate, long contentLength, ChannelListener<? super FixedLengthStreamSourceChannel> finishListener, java.lang.Object guard)
#drain()
method if the underlying stream is to be reused.
Calling this constructor will replace the read listener of the underlying channel. The listener should be
restored from the finishListener
object. The underlying stream should not be closed while this wrapper
stream is active.
delegate
- the stream source channel to read fromcontentLength
- the amount of content to readfinishListener
- the listener to call once the stream is exhausted or closedguard
- the guard object to usepublic FixedLengthStreamSourceChannel(StreamSourceChannel delegate, long contentLength, boolean configurable, ChannelListener<? super FixedLengthStreamSourceChannel> finishListener, java.lang.Object guard)
#drain()
method if the underlying stream is to be reused.
Calling this constructor will replace the read listener of the underlying channel. The listener should be
restored from the finishListener
object. The underlying stream should not be closed while this wrapper
stream is active.
delegate
- the stream source channel to read fromcontentLength
- the amount of content to readconfigurable
- true
to allow options to pass through to the delegate, false
otherwisefinishListener
- the listener to call once the stream is exhausted or closedguard
- the guard object to usepublic FixedLengthStreamSourceChannel(StreamSourceChannel delegate, long contentLength, boolean configurable, boolean propagateClose, ChannelListener<? super FixedLengthStreamSourceChannel> finishListener, java.lang.Object guard)
#drain()
method if the underlying stream is to be reused.
Calling this constructor will replace the read listener of the underlying channel. The listener should be
restored from the finishListener
object. The underlying stream should not be closed while this wrapper
stream is active.
delegate
- the stream source channel to read fromcontentLength
- the amount of content to readconfigurable
- true
to allow options to pass through to the delegate, false
otherwisepropagateClose
- true
to propagate close/shutdown to the delegate, false
otherwisefinishListener
- the listener to call once the stream is exhausted or closedguard
- the guard object to usepublic void setReadListener(ChannelListener<? super FixedLengthStreamSourceChannel> readListener)
ReadListenerSettable
setReadListener
in interface ReadListenerSettable<FixedLengthStreamSourceChannel>
readListener
- the read listenerpublic ChannelListener<? super FixedLengthStreamSourceChannel> getReadListener()
ReadListenerSettable
getReadListener
in interface ReadListenerSettable<FixedLengthStreamSourceChannel>
public void setCloseListener(ChannelListener<? super FixedLengthStreamSourceChannel> closeListener)
CloseListenerSettable
setCloseListener
in interface CloseListenerSettable<FixedLengthStreamSourceChannel>
closeListener
- the close listenerpublic ChannelListener<? super FixedLengthStreamSourceChannel> getCloseListener()
CloseListenerSettable
getCloseListener
in interface CloseListenerSettable<FixedLengthStreamSourceChannel>
public ChannelListener.Setter<FixedLengthStreamSourceChannel> getReadSetter()
StreamSourceChannel
getReadSetter
in interface StreamSourceChannel
getReadSetter
in interface SuspendableReadChannel
public ChannelListener.Setter<FixedLengthStreamSourceChannel> getCloseSetter()
StreamSourceChannel
getCloseSetter
in interface CloseableChannel
getCloseSetter
in interface StreamSourceChannel
getCloseSetter
in interface SuspendableReadChannel
public long transferTo(long position, long count, FileChannel target) throws java.io.IOException
StreamSourceChannel
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 InterruptedIOException
;
however, if this exception is thrown, the InterruptedIOException.bytesTransferred
field is
guaranteed to be 0.
transferTo
in interface StreamSourceChannel
position
- 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
StreamSourceChannel
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 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 StreamSourceChannel
count
- 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 read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
read
in interface java.nio.channels.ScatteringByteChannel
java.io.IOException
public long read(java.nio.ByteBuffer[] dsts) throws java.io.IOException
read
in interface java.nio.channels.ScatteringByteChannel
java.io.IOException
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
java.io.IOException
public void suspendReads()
SuspendableReadChannel
suspendReads
in interface SuspendableReadChannel
public void resumeReads()
SuspendableReadChannel
resumeReads
in interface SuspendableReadChannel
public boolean isReadResumed()
SuspendableReadChannel
isReadResumed
in interface SuspendableReadChannel
true
if reads are resumed, false
if reads are suspendedpublic void wakeupReads()
SuspendableReadChannel
Resume reads
on this channel, and force the read listener to be triggered even if the
channel isn't actually readable.wakeupReads
in interface SuspendableReadChannel
public void shutdownReads() throws java.io.IOException
SuspendableReadChannel
CloseableChannel.close()
to be called automatically.shutdownReads
in interface SuspendableReadChannel
java.io.IOException
- if an I/O error occurspublic void awaitReadable() throws java.io.IOException
SuspendableReadChannel
awaitReadable
in interface SuspendableReadChannel
java.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
SuspendableReadChannel
awaitReadable
in interface SuspendableReadChannel
time
- 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()
SuspendableReadChannel
getReadThread
in interface SuspendableReadChannel
null
if none is configured or availablepublic XnioIoThread getIoThread()
CloseableChannel
getIoThread
in interface CloseableChannel
public XnioWorker getWorker()
CloseableChannel
getWorker
in interface CloseableChannel
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.IOException
CloseableChannel
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
close
in interface java.nio.channels.InterruptibleChannel
close
in interface CloseableChannel
java.io.IOException
- if the close failedpublic boolean supportsOption(Option<?> option)
Configurable
supportsOption
in interface Configurable
option
- the optiontrue
if it is supportedpublic <T> T getOption(Option<T> option) throws java.io.IOException
Configurable
getOption
in interface Configurable
T
- 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
Configurable
setOption
in interface Configurable
T
- 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 optionpublic StreamSourceChannel getChannel(java.lang.Object guard)
ProtectedWrappedChannel
null
if the guard is invalid.getChannel
in interface ProtectedWrappedChannel<StreamSourceChannel>
guard
- the guard objectpublic long getRemaining()
Copyright © 2016 JBoss, a division of Red Hat, Inc.