Package io.undertow.conduits
Class FixedLengthStreamSourceConduit
- java.lang.Object
-
- org.xnio.conduits.AbstractConduit<D>
-
- org.xnio.conduits.AbstractSourceConduit<D>
-
- org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>
-
- io.undertow.conduits.FixedLengthStreamSourceConduit
-
- All Implemented Interfaces:
org.xnio.conduits.Conduit,org.xnio.conduits.SourceConduit,org.xnio.conduits.StreamSourceConduit
public final class FixedLengthStreamSourceConduit extends org.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>A channel which reads data of a fixed length and calls a finish listener. When the finish listener is called, it should examine the result ofgetRemaining()to see if more bytes were pending when the channel was closed.- Author:
- David M. Lloyd, Flavia Rainone
-
-
Constructor Summary
Constructors Constructor Description FixedLengthStreamSourceConduit(org.xnio.conduits.StreamSourceConduit next, long contentLength, ConduitListener<? super FixedLengthStreamSourceConduit> finishListener)Construct a new instance.FixedLengthStreamSourceConduit(org.xnio.conduits.StreamSourceConduit next, long contentLength, ConduitListener<? super FixedLengthStreamSourceConduit> finishListener, HttpServerExchange exchange)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawaitReadable()voidawaitReadable(long time, TimeUnit timeUnit)longgetRemaining()Get the number of remaining bytes.booleanisReadResumed()intread(ByteBuffer dst)longread(ByteBuffer[] dsts)longread(ByteBuffer[] dsts, int offset, int length)voidresumeReads()voidterminateReads()longtransferTo(long position, long count, FileChannel target)longtransferTo(long count, ByteBuffer throughBuffer, org.xnio.channels.StreamSinkChannel target)voidwakeupReads()-
Methods inherited from class org.xnio.conduits.AbstractSourceConduit
getReadThread, isReadShutdown, setReadReadyHandler, suspendReads
-
-
-
-
Constructor Detail
-
FixedLengthStreamSourceConduit
public FixedLengthStreamSourceConduit(org.xnio.conduits.StreamSourceConduit next, long contentLength, ConduitListener<? super FixedLengthStreamSourceConduit> finishListener, HttpServerExchange exchange)Construct a new instance. The given listener is called once all the bytes are read from the stream or the stream is closed. This listener should cause the remaining data to be drained from the underlying stream 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
finishListenerobject. The underlying stream should not be closed while this wrapper stream is active.- Parameters:
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 size
-
FixedLengthStreamSourceConduit
public FixedLengthStreamSourceConduit(org.xnio.conduits.StreamSourceConduit next, long contentLength, ConduitListener<? super FixedLengthStreamSourceConduit> finishListener)Construct a new instance. The given listener is called once all the bytes are read from the stream or the stream is closed. This listener should cause the remaining data to be drained from the underlying stream 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
finishListenerobject. The underlying stream should not be closed while this wrapper stream is active.- Parameters:
next- the stream source channel to read fromcontentLength- the amount of content to readfinishListener- the listener to call once the stream is exhausted or closed
-
-
Method Detail
-
transferTo
public long transferTo(long position, long count, FileChannel target) throws IOException- Specified by:
transferToin interfaceorg.xnio.conduits.StreamSourceConduit- Overrides:
transferToin classorg.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
transferTo
public long transferTo(long count, ByteBuffer throughBuffer, org.xnio.channels.StreamSinkChannel target) throws IOException- Specified by:
transferToin interfaceorg.xnio.conduits.StreamSourceConduit- Overrides:
transferToin classorg.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
read
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException
- Specified by:
readin interfaceorg.xnio.conduits.StreamSourceConduit- Overrides:
readin classorg.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
read
public long read(ByteBuffer[] dsts) throws IOException
- Throws:
IOException
-
read
public int read(ByteBuffer dst) throws IOException
- Specified by:
readin interfaceorg.xnio.conduits.StreamSourceConduit- Overrides:
readin classorg.xnio.conduits.AbstractStreamSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
isReadResumed
public boolean isReadResumed()
- Specified by:
isReadResumedin interfaceorg.xnio.conduits.SourceConduit- Overrides:
isReadResumedin classorg.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
-
wakeupReads
public void wakeupReads()
- Specified by:
wakeupReadsin interfaceorg.xnio.conduits.SourceConduit- Overrides:
wakeupReadsin classorg.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
-
resumeReads
public void resumeReads()
- Specified by:
resumeReadsin interfaceorg.xnio.conduits.SourceConduit- Overrides:
resumeReadsin classorg.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>
-
terminateReads
public void terminateReads() throws IOException- Specified by:
terminateReadsin interfaceorg.xnio.conduits.SourceConduit- Overrides:
terminateReadsin classorg.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
awaitReadable
public void awaitReadable() throws IOException- Specified by:
awaitReadablein interfaceorg.xnio.conduits.SourceConduit- Overrides:
awaitReadablein classorg.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
awaitReadable
public void awaitReadable(long time, TimeUnit timeUnit) throws IOException- Specified by:
awaitReadablein interfaceorg.xnio.conduits.SourceConduit- Overrides:
awaitReadablein classorg.xnio.conduits.AbstractSourceConduit<org.xnio.conduits.StreamSourceConduit>- Throws:
IOException
-
getRemaining
public long getRemaining()
Get the number of remaining bytes.- Returns:
- the number of remaining bytes
-
-