Top Inners Fields Constructors Methods
io.undertow.protocols.http2

public Class Http2StreamSourceChannel

extends AbstractHttp2StreamSourceChannel
implements Http2Stream
Class Inheritance
All Implemented Interfaces
io.undertow.protocols.http2.Http2Stream
Imports
io.undertow.UndertowLogger, io.undertow.connector.PooledByteBuffer, io.undertow.server.protocol.framed.FrameHeaderData, io.undertow.util.HeaderMap, .Headers, org.xnio.Bits, .ChannelListener, .ChannelListeners, .IoUtils, org.xnio.channels.StreamSinkChannel, java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private ChannelListener<Http2StreamSourceChannel>
private long
private int
private final HeaderMap
private boolean
headersEndStream

Flag that is set if the headers frame has the end stream flag set, but not end headers which means the last continuation frame is the end of the stream.

private boolean
ignoreForceClose

This is a bit of a hack, basically it allows the container to delay sending a RST_STREAM on a channel that is knows is broken, because it wants to delay the RST until after the response has been set Used for handling the super nasty 100-continue logic

private int
private Http2HeadersStreamSinkChannel
private boolean
private final int
private Http2StreamSourceChannel.TrailersHandler

Constructor Summary

AccessConstructor and Description
pack-priv
Http2StreamSourceChannel(Http2Channel framedChannel, PooledByteBuffer data, long frameDataRemaining, HeaderMap headers, int streamId)

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
complete()

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.complete.

Method that is invoked when all data has been read.

public ChannelListener<Http2StreamSourceChannel>
public HeaderMap
public Http2HeadersStreamSinkChannel
public int
public Http2StreamSourceChannel.TrailersHandler
pack-priv void
protected void
pack-priv boolean
public boolean
public int
read(ByteBuffer
The buffer into which bytes are to be transferred
dst
)

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.read.

Implements java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

public long
read(ByteBuffer[]
The buffers into which bytes are to be transferred
dsts
,
int
The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset
length
)

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.read.

Implements java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

public long
read(ByteBuffer[]
The buffers into which bytes are to be transferred
dsts
)

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.read.

Implements java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into the given buffers.

pack-priv void
public void
public void
setIgnoreForceClose(boolean ignoreForceClose)

public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

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

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.transferTo.

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given channel target.

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

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.transferTo.

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given file from this channel.

pack-priv void
updateContentSize(long
The amount of data in the frame
frameLength
,
boolean
If this is the last frame
last
)

Checks that the actual content size matches the expected.

private void
updateFlowControlWindow(final int read)

protected long
Inherited from io.undertow.protocols.http2.AbstractHttp2StreamSourceChannel:
getFramedChannelgetHttp2ChannellastFramemarkStreamBrokenrstStream

Field Detail

completionListenerback to summary
private ChannelListener<Http2StreamSourceChannel> completionListener
contentLengthRemainingback to summary
private long contentLengthRemaining
flowControlWindowback to summary
private int flowControlWindow
headersback to summary
private final HeaderMap headers
headersEndStreamback to summary
private boolean headersEndStream

Flag that is set if the headers frame has the end stream flag set, but not end headers which means the last continuation frame is the end of the stream.

ignoreForceCloseback to summary
private boolean ignoreForceClose

This is a bit of a hack, basically it allows the container to delay sending a RST_STREAM on a channel that is knows is broken, because it wants to delay the RST until after the response has been set Used for handling the super nasty 100-continue logic

remainingPaddingback to summary
private int remainingPadding
responseback to summary
private Http2HeadersStreamSinkChannel response
rstback to summary
private boolean rst
streamIdback to summary
private final int streamId
trailersHandlerback to summary
private Http2StreamSourceChannel.TrailersHandler trailersHandler

Constructor Detail

Http2StreamSourceChannelback to summary
pack-priv Http2StreamSourceChannel(Http2Channel framedChannel, PooledByteBuffer data, long frameDataRemaining, HeaderMap headers, int streamId)

Method Detail

channelForciblyClosedback to summary
protected void channelForciblyClosed()

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.channelForciblyClosed.

Annotations
@Override
completeback to summary
protected void complete() throws IOException

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.complete.

Doc from io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.complete.

Method that is invoked when all data has been read.

Annotations
@Override
getCompletionListenerback to summary
public ChannelListener<Http2StreamSourceChannel> getCompletionListener()
getHeadersback to summary
public HeaderMap getHeaders()
getResponseChannelback to summary
public Http2HeadersStreamSinkChannel getResponseChannel()
getStreamIdback to summary
public int getStreamId()

Implements io.undertow.protocols.http2.Http2Stream.getStreamId.

getTrailersHandlerback to summary
public Http2StreamSourceChannel.TrailersHandler getTrailersHandler()
handleFinalFrameback to summary
pack-priv void handleFinalFrame(Http2FrameHeaderParser headerData)
handleHeaderDataback to summary
protected void handleHeaderData(FrameHeaderData headerData)

Overrides io.undertow.protocols.http2.AbstractHttp2StreamSourceChannel.handleHeaderData.

Annotations
@Override
isHeadersEndStreamback to summary
pack-priv boolean isHeadersEndStream()
isIgnoreForceCloseback to summary
public boolean isIgnoreForceClose()
readback to summary
public int read(ByteBuffer dst) throws IOException

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.read.

Implements java.nio.channels.ReadableByteChannel.read.

Doc from java.nio.channels.ReadableByteChannel.read.

Reads a sequence of bytes from this channel into the given buffer.

An attempt is made to read up to r bytes from the channel, where r is the number of bytes remaining in the buffer, that is, dst.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. This byte sequence will be transferred into the buffer so that the first byte in the sequence is at index p and the last byte is at index p + n - 1, where p is the buffer's position at the moment this method is invoked. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

A read operation might not fill the buffer, and in fact it might not read any bytes at all. Whether or not it does so depends upon the nature and state of the channel. A socket channel in non-blocking mode, for example, cannot read any more bytes than are immediately available from the socket's input buffer; similarly, a file channel cannot read any more bytes than remain in the file. It is guaranteed, however, that if a channel is in blocking mode and there is at least one byte remaining in the buffer then this method will block until at least one byte is read.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
dst:ByteBuffer

The buffer into which bytes are to be transferred

Returns:int

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readback to summary
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.read.

Implements java.nio.channels.ScatteringByteChannel.read.

Doc from java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into a subsequence of the given buffers.

An invocation of this method attempts to read up to r bytes from this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,

dsts[offset].remaining() + dsts[offset+1].remaining() + ... + dsts[offset+length-1].remaining()
dsts[offset].remaining()
    + dsts[offset+1].remaining()
    + ... + dsts[offset+length-1].remaining()
at the moment that this method is invoked.

Suppose that a byte sequence of length n is read, where 0 <= n <= r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit.

This method may be invoked at any time. If another thread has already initiated a read operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
dsts:ByteBuffer[]

The buffers into which bytes are to be transferred

offset:int

The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than dsts.length

length:int

The maximum number of buffers to be accessed; must be non-negative and no larger than dsts.length - offset

Returns:long

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
readback to summary
public long read(ByteBuffer[] dsts) throws IOException

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.read.

Implements java.nio.channels.ScatteringByteChannel.read.

Doc from java.nio.channels.ScatteringByteChannel.read.

Reads a sequence of bytes from this channel into the given buffers.

An invocation of this method of the form c.read(dsts) behaves in exactly the same manner as the invocation

c.read(dsts, 0, dsts.length);
c.read(dsts, 0, dsts.length);
Parameters
dsts:ByteBuffer[]

The buffers into which bytes are to be transferred

Returns:long

The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
rstStreamback to summary
pack-priv void rstStream(int error)

Overrides io.undertow.protocols.http2.AbstractHttp2StreamSourceChannel.rstStream.

Annotations
@Override
setCompletionListenerback to summary
public void setCompletionListener(ChannelListener<Http2StreamSourceChannel> completionListener)
setIgnoreForceCloseback to summary
public void setIgnoreForceClose(boolean ignoreForceClose)
setTrailersHandlerback to summary
public void setTrailersHandler(Http2StreamSourceChannel.TrailersHandler trailersHandler)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
transferToback to summary
public long transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel streamSinkChannel) throws IOException

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.transferTo.

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Doc from org.xnio.channels.StreamSourceChannel.transferTo.

Transfers 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 the 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 java.io.InterruptedIOException; however, if this exception is thrown, the java.io.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.

Parameters
count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

streamSinkChannel: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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
transferToback to summary
public long transferTo(long position, long count, FileChannel target) throws IOException

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.transferTo.

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Doc from org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given file from this channel. Using this method in preference to 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 java.io.InterruptedIOException; however, if this exception is thrown, the java.io.InterruptedIOException#bytesTransferred field is guaranteed to be 0.

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
updateContentSizeback to summary
pack-priv void updateContentSize(long frameLength, boolean last)

Checks that the actual content size matches the expected. We check this proactivly, rather than as the data is read

Parameters
frameLength:long

The amount of data in the frame

last:boolean

If this is the last frame

updateFlowControlWindowback to summary
private void updateFlowControlWindow(final int read) throws IOException
updateFrameDataRemainingback to summary
protected long updateFrameDataRemaining(PooledByteBuffer data, long frameDataRemaining)

Overrides io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel.updateFrameDataRemaining.

Annotations
@Override
io.undertow.protocols.http2 back to summary

public Interface Http2StreamSourceChannel.TrailersHandler


Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

handleTrailersback to summary
public void handleTrailers(HeaderMap headerMap)