Top Description Inners Fields Constructors Methods
io.undertow.websockets.core

public abstract Class StreamSourceFrameChannel

extends AbstractFramedStreamSourceChannel<WebSocketChannel, StreamSourceFrameChannel, StreamSinkFrameChannel>
Class Inheritance
Known Direct Subclasses
io.undertow.websockets.core.protocol.version07.WebSocket07BinaryFrameSourceChannel, io.undertow.websockets.core.protocol.version07.WebSocket07CloseFrameSourceChannel, io.undertow.websockets.core.protocol.version07.WebSocket07PingFrameSourceChannel, io.undertow.websockets.core.protocol.version07.WebSocket07PongFrameSourceChannel, io.undertow.websockets.core.protocol.version07.WebSocket07TextFrameSourceChannel
Imports
java.io.IOException, .UnsupportedEncodingException, java.nio.ByteBuffer, java.nio.channels.FileChannel, io.undertow.connector.PooledByteBuffer, io.undertow.websockets.core.function.ChannelFunction, .ChannelFunctionFileChannel, io.undertow.websockets.core.protocol.version07.Masker, .UTF8Checker, io.undertow.websockets.extensions.ExtensionFunction, .NoopExtensionFunction, org.xnio.channels.StreamSinkChannel, io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel, .FrameHeaderData

Base class for processes Frame bases StreamSourceChannels.
Author
Norman Maurer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private UTF8Checker
private final ExtensionFunction
private boolean
private final ChannelFunction[]
private Masker
private final int
protected final WebSocketFrameType

Constructor Summary

AccessConstructor and Description
protected
protected
StreamSourceFrameChannel(WebSocketChannel wsChannel, WebSocketFrameType type, int rsv, boolean finalFragment, PooledByteBuffer pooled, long frameLength, Masker masker, ChannelFunction... functions)

Method Summary

Modifier and TypeMethod and Description
protected void
afterRead(ByteBuffer
the ByteBuffer into which the data was read
buffer
,
int
the position it was written to
position
,
int
the number of bytes there were written
length
)

Called after data was read into the ByteBuffer

private void
protected void
checker(ByteBuffer buffer, int position, int length, boolean complete)

public void
protected WebSocketChannel
public int
getRsv()

Return the rsv which is used for extensions.

public WebSocketFrameType
getType()

Return the WebSocketFrameType or null if its not known at the calling time.

public WebSocketChannel
pack-priv int
protected void
public boolean
isFinalFragment()

Flag to indicate if this frame is the final fragment in a message.

protected PooledByteBuffer
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 final 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.

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 final 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.

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

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

Implements org.xnio.channels.StreamSourceChannel.transferTo.

Transfers bytes into the given channel target.

Inherited from io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel:
addCloseTaskawaitReadableawaitReadablechannelForciblyClosedclosecompletedataReadygetCloseSettergetIoThreadgetMaxStreamSizegetOptiongetReadFrameCountgetReadSettergetReadThreadgetWorkerisCompleteisLastFrameisOpenisReadResumedlastFramemarkStreamBrokenresumeReadssetMaxStreamSizesetOptionshutdownReadssupportsOptionsuspendReadsupdateFrameDataRemainingwakeupReads

Field Detail

checkerback to summary
private UTF8Checker checker
extensionFunctionback to summary
private final ExtensionFunction extensionFunction
finalFragmentback to summary
private boolean finalFragment
functionsback to summary
private final ChannelFunction[] functions
maskerback to summary
private Masker masker
rsvback to summary
private final int rsv
typeback to summary
protected final WebSocketFrameType type

Constructor Detail

StreamSourceFrameChannelback to summary
protected StreamSourceFrameChannel(WebSocketChannel wsChannel, WebSocketFrameType type, PooledByteBuffer pooled, long frameLength)
StreamSourceFrameChannelback to summary
protected StreamSourceFrameChannel(WebSocketChannel wsChannel, WebSocketFrameType type, int rsv, boolean finalFragment, PooledByteBuffer pooled, long frameLength, Masker masker, ChannelFunction... functions)

Method Detail

afterReadback to summary
protected void afterRead(ByteBuffer buffer, int position, int length) throws IOException

Called after data was read into the ByteBuffer

Parameters
buffer:ByteBuffer

the ByteBuffer into which the data was read

position:int

the position it was written to

length:int

the number of bytes there were written

Exceptions
IOException:
thrown if an error occurs
checkCompleteback to summary
private void checkComplete() throws IOException
checkerback to summary
protected void checker(ByteBuffer buffer, int position, int length, boolean complete) throws IOException
finalFrameback to summary
public void finalFrame()
getFramedChannelback to summary
protected WebSocketChannel getFramedChannel()

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

Annotations
@Override
getRsvback to summary
public int getRsv()

Return the rsv which is used for extensions.

getTypeback to summary
public WebSocketFrameType getType()

Return the WebSocketFrameType or null if its not known at the calling time.

getWebSocketChannelback to summary
public WebSocketChannel getWebSocketChannel()
getWebSocketFrameCountback to summary
pack-priv int getWebSocketFrameCount()
handleHeaderDataback to summary
protected void handleHeaderData(FrameHeaderData headerData)

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

Annotations
@Override
isFinalFragmentback to summary
public boolean isFinalFragment()

Flag to indicate if this frame is the final fragment in a message. The first fragment (frame) may also be the final fragment.

processFrameDataback to summary
protected PooledByteBuffer processFrameData(PooledByteBuffer frameData, boolean lastFragmentOfFrame) throws IOException

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

Annotations
@Override
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 final 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
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
transferToback to summary
public final 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
transferToback to summary
public final long transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel 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 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.

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
io.undertow.websockets.core back to summary

private Class StreamSourceFrameChannel.Bounds

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
Bounds(int position, int limit)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

limitback to summary
pack-priv final int limit
positionback to summary
pack-priv final int position

Constructor Detail

Boundsback to summary
pack-priv Bounds(int position, int limit)