public final class FixedLengthStreamSourceConduit extends AbstractStreamSourceConduit<StreamSourceConduit>
getRemaining()
to see if more bytes were pending when the channel was
closed.next
Constructor and Description |
---|
FixedLengthStreamSourceConduit(StreamSourceConduit next,
long contentLength,
ConduitListener<? super FixedLengthStreamSourceConduit> finishListener)
Construct a new instance.
|
FixedLengthStreamSourceConduit(StreamSourceConduit next,
long contentLength,
ConduitListener<? super FixedLengthStreamSourceConduit> finishListener,
HttpServerExchange exchange)
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
awaitReadable()
Block until this channel becomes readable again.
|
void |
awaitReadable(long time,
TimeUnit timeUnit)
Block until this conduit becomes readable again, or until the timeout expires.
|
long |
getRemaining()
Get the number of remaining bytes.
|
boolean |
isReadResumed()
Determine whether read notifications are currently enabled.
|
int |
read(ByteBuffer dst)
Read a sequence of bytes from this conduit to the given buffer.
|
long |
read(ByteBuffer[] dsts) |
long |
read(ByteBuffer[] dsts,
int offset,
int length)
Read a sequence of bytes from this conduit to the given buffers.
|
void |
terminateReads()
Indicate that no more data will be read from this conduit.
|
long |
transferTo(long count,
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()
Indicate that the conduit's
ReadReadyHandler should be invoked immediately, and then again as soon
as data can be read without blocking. |
getReadThread, isReadShutdown, resumeReads, setReadReadyHandler, suspendReads
getWorker
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getReadThread, isReadShutdown, resumeReads, setReadReadyHandler, suspendReads
public FixedLengthStreamSourceConduit(StreamSourceConduit next, long contentLength, ConduitListener<? super FixedLengthStreamSourceConduit> finishListener, HttpServerExchange exchange)
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.
next
- the stream source channel to read fromcontentLength
- the amount of content to readfinishListener
- the listener to call once the stream is exhausted or closedexchange
- The server exchange. This is used to determine the max sizepublic FixedLengthStreamSourceConduit(StreamSourceConduit next, long contentLength, ConduitListener<? super FixedLengthStreamSourceConduit> finishListener)
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.
next
- the stream source channel to read fromcontentLength
- the amount of content to readfinishListener
- the listener to call once the stream is exhausted or closedpublic long transferTo(long position, long count, FileChannel target) throws IOException
StreamSourceConduit
transferTo
in interface StreamSourceConduit
transferTo
in class AbstractStreamSourceConduit<StreamSourceConduit>
position
- the position within the file from which the transfer is to begincount
- the number of bytes to be transferredtarget
- the file to write toIOException
- if an I/O error occurspublic long transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel target) throws IOException
StreamSourceConduit
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.transferTo
in interface StreamSourceConduit
transferTo
in class AbstractStreamSourceConduit<StreamSourceConduit>
count
- the number of bytes to be transferredthroughBuffer
- the buffer to copy through.target
- the destination to write toIOException
- if an I/O error occurspublic long read(ByteBuffer[] dsts, int offset, int length) throws IOException
StreamSourceConduit
read
in interface StreamSourceConduit
read
in class AbstractStreamSourceConduit<StreamSourceConduit>
offset
- the offset into the buffer arraylength
- the number of buffers to fillSourceConduit.terminateReads()
method was previously calledIOException
- if an error occurspublic long read(ByteBuffer[] dsts) throws IOException
IOException
public int read(ByteBuffer dst) throws IOException
StreamSourceConduit
read
in interface StreamSourceConduit
read
in class AbstractStreamSourceConduit<StreamSourceConduit>
SourceConduit.terminateReads()
method was previously calledIOException
- if an error occurspublic boolean isReadResumed()
SourceConduit
isReadResumed
in interface SourceConduit
isReadResumed
in class AbstractSourceConduit<StreamSourceConduit>
true
if read notifications are enabledpublic void wakeupReads()
SourceConduit
ReadReadyHandler
should be invoked immediately, and then again as soon
as data can be read without blocking.wakeupReads
in interface SourceConduit
wakeupReads
in class AbstractSourceConduit<StreamSourceConduit>
public void terminateReads() throws IOException
SourceConduit
terminateReads
in interface SourceConduit
terminateReads
in class AbstractSourceConduit<StreamSourceConduit>
IOException
- if there was a problempublic void awaitReadable() throws IOException
SourceConduit
awaitReadable
in interface SourceConduit
awaitReadable
in class AbstractSourceConduit<StreamSourceConduit>
InterruptedIOException
- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException
- if an I/O error occurspublic void awaitReadable(long time, TimeUnit timeUnit) throws IOException
SourceConduit
awaitReadable
in interface SourceConduit
awaitReadable
in class AbstractSourceConduit<StreamSourceConduit>
time
- the time to waittimeUnit
- the time unitInterruptedIOException
- if the operation is interrupted; the thread's interrupt flag will be set as wellIOException
- if an I/O error occurspublic long getRemaining()
Copyright © 2017 JBoss by Red Hat. All rights reserved.