Top Description Fields Constructors Methods
io.undertow.conduits

public final Class FixedLengthStreamSourceConduit

extends AbstractStreamSourceConduit<StreamSourceConduit>
Class Inheritance
Imports
io.undertow.UndertowMessages, io.undertow.server.Connectors, .HttpServerExchange, org.xnio.IoUtils, org.xnio.channels.StreamSinkChannel, org.xnio.conduits.AbstractStreamSourceConduit, .StreamSourceConduit, java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.util.concurrent.TimeUnit

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 of getRemaining() to see if more bytes were pending when the channel was closed.
Authors
David M. Lloyd, Flavia Rainone

Field Summary

Modifier and TypeField and Description
private final HttpServerExchange
private final ConduitListener<? super FixedLengthStreamSourceConduit>
private static final long
private static final long
private static final long
private static final long
private long

Constructor Summary

AccessConstructor and Description
public
FixedLengthStreamSourceConduit(final StreamSourceConduit
the stream source channel to read from
next
,
final long
the amount of content to read
contentLength
,
final ConduitListener<? super FixedLengthStreamSourceConduit>
the listener to call once the stream is exhausted or closed
finishListener
,
final HttpServerExchange
The server exchange. This is used to determine the max size
exchange
)

Construct a new instance.

public
FixedLengthStreamSourceConduit(final StreamSourceConduit
the stream source channel to read from
next
,
final long
the amount of content to read
contentLength
,
final ConduitListener<? super FixedLengthStreamSourceConduit>
the listener to call once the stream is exhausted or closed
finishListener
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public void
awaitReadable()

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again.

public void
awaitReadable(final long
the time to wait
time
,
final TimeUnit
the time unit
timeUnit
)

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this conduit becomes readable again, or until the timeout expires.

private void
checkMaxSize(long state)

private void
private long
private void
exitRead(long
the number of bytes consumed by this call (may be 0)
consumed
,
Throwable
IOException, RuntimeException or Error thrown during read operation
readError
)

Exit a read method.

private void
exitShutdownReads(long oldVal)

public long

Returns:

the number of remaining bytes
getRemaining
()

Get the number of remaining bytes.

private void
public boolean
isReadResumed()

Overrides org.xnio.conduits.AbstractSourceConduit.isReadResumed.

Implements org.xnio.conduits.SourceConduit.isReadResumed.

Determine whether read notifications are currently enabled.

public long
read(final ByteBuffer[]
the buffers to fill with data from the conduit
dsts
,
final int
the offset into the buffer array
offset
,
final int
the number of buffers to fill
length
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffers.

public long
read(final ByteBuffer[] dsts)

public int
read(final ByteBuffer
the buffer to fill with data from the conduit
dst
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffer.

public void
resumeReads()

Overrides org.xnio.conduits.AbstractSourceConduit.resumeReads.

Implements org.xnio.conduits.SourceConduit.resumeReads.

Indicate that the conduit's ReadReadyHandler should be invoked as soon as data can be read without blocking.

public void
terminateReads()

Overrides org.xnio.conduits.AbstractSourceConduit.terminateReads.

Implements org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit.

public long
transferTo(final long
the position within the file from which the transfer is to begin
position
,
final long
the number of bytes to be transferred
count
,
final FileChannel
the file to write to
target
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

public long
transferTo(final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
,
final StreamSinkChannel
the destination to write to
target
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given channel target.

public void
wakeupReads()

Overrides org.xnio.conduits.AbstractSourceConduit.wakeupReads.

Implements org.xnio.conduits.SourceConduit.wakeupReads.

Indicate that the conduit's ReadReadyHandler should be invoked immediately, and then again as soon as data can be read without blocking.

Field Detail

exchangeback to summary
private final HttpServerExchange exchange
finishListenerback to summary
private final ConduitListener<? super FixedLengthStreamSourceConduit> finishListener
FLAG_CLOSEDback to summary
private static final long FLAG_CLOSED
FLAG_FINISHEDback to summary
private static final long FLAG_FINISHED
FLAG_LENGTH_CHECKEDback to summary
private static final long FLAG_LENGTH_CHECKED
MASK_COUNTback to summary
private static final long MASK_COUNT
stateback to summary
private long state
Annotations
@SuppressWarnings:unused

Constructor Detail

FixedLengthStreamSourceConduitback to summary
public FixedLengthStreamSourceConduit(final StreamSourceConduit next, final long contentLength, final ConduitListener<? super FixedLengthStreamSourceConduit> finishListener, final 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 finishListener object. The underlying stream should not be closed while this wrapper stream is active.

Parameters
next:StreamSourceConduit

the stream source channel to read from

contentLength:long

the amount of content to read

finishListener:ConduitListener<? super FixedLengthStreamSourceConduit>

the listener to call once the stream is exhausted or closed

exchange:HttpServerExchange

The server exchange. This is used to determine the max size

FixedLengthStreamSourceConduitback to summary
public FixedLengthStreamSourceConduit(final StreamSourceConduit next, final long contentLength, final 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 finishListener object. The underlying stream should not be closed while this wrapper stream is active.

Parameters
next:StreamSourceConduit

the stream source channel to read from

contentLength:long

the amount of content to read

finishListener:ConduitListener<? super FixedLengthStreamSourceConduit>

the listener to call once the stream is exhausted or closed

Method Detail

awaitReadableback to summary
public void awaitReadable() throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.

Exceptions
IOException:
if an I/O error occurs
awaitReadableback to summary
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

Block until this conduit becomes readable again, or until the timeout expires. This method may return spuriously before the conduit becomes readable or the timeout expires.

Parameters
time:long

the time to wait

timeUnit:TimeUnit

the time unit

Exceptions
IOException:
if an I/O error occurs
checkMaxSizeback to summary
private void checkMaxSize(long state) throws IOException
closeConnectionback to summary
private void closeConnection()
enterShutdownReadsback to summary
private long enterShutdownReads()
exitReadback to summary
private void exitRead(long consumed, Throwable readError) throws IOException

Exit a read method.

Parameters
consumed:long

the number of bytes consumed by this call (may be 0)

readError:Throwable

IOException, RuntimeException or Error thrown during read operation

Exceptions
IOException:
if this conduit has not finished reading all the bytes. In this case, if readError is not null, it is added as a suppressed throwable of this exception
exitShutdownReadsback to summary
private void exitShutdownReads(long oldVal)
getRemainingback to summary
public long getRemaining()

Get the number of remaining bytes.

Returns:long

the number of remaining bytes

invokeFinishListenerback to summary
private void invokeFinishListener()
isReadResumedback to summary
public boolean isReadResumed()

Overrides org.xnio.conduits.AbstractSourceConduit.isReadResumed.

Implements org.xnio.conduits.SourceConduit.isReadResumed.

Doc from org.xnio.conduits.SourceConduit.isReadResumed.

Determine whether read notifications are currently enabled.

Returns:boolean

true if read notifications are enabled

readback to summary
public long read(final ByteBuffer[] dsts, final int offset, final int length) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffers.

Parameters
dsts:ByteBuffer[]

the buffers to fill with data from the conduit

offset:int

the offset into the buffer array

length:int

the number of buffers to fill

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Exceptions
IOException:
if an error occurs
readback to summary
public long read(final ByteBuffer[] dsts) throws IOException
readback to summary
public int read(final ByteBuffer dst) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffer.

Parameters
dst:ByteBuffer

the buffer to fill with data from the conduit

Returns:int

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Exceptions
IOException:
if an error occurs
resumeReadsback to summary
public void resumeReads()

Overrides org.xnio.conduits.AbstractSourceConduit.resumeReads.

Implements org.xnio.conduits.SourceConduit.resumeReads.

Doc from org.xnio.conduits.SourceConduit.resumeReads.

Indicate that the conduit's ReadReadyHandler should be invoked as soon as data can be read without blocking.

Annotations
@Override
terminateReadsback to summary
public void terminateReads() throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.terminateReads.

Implements org.xnio.conduits.SourceConduit.terminateReads.

Doc from org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit. If unread data exists, an exception may be thrown.

Annotations
@Override
Exceptions
IOException:
if there was a problem
transferToback to summary
public long transferTo(final long position, final long count, final FileChannel target) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

Parameters
position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

target:FileChannel

the file to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred

Exceptions
IOException:
if an I/O error occurs
transferToback to summary
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given channel target. 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.

Parameters
count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

target:StreamSinkChannel

the destination to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Exceptions
IOException:
if an I/O error occurs
wakeupReadsback to summary
public void wakeupReads()

Overrides org.xnio.conduits.AbstractSourceConduit.wakeupReads.

Implements org.xnio.conduits.SourceConduit.wakeupReads.

Doc from org.xnio.conduits.SourceConduit.wakeupReads.

Indicate that the conduit's ReadReadyHandler should be invoked immediately, and then again as soon as data can be read without blocking.