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

public final Class WebSocketUtils

extends Object
Class Inheritance
Imports
io.undertow.UndertowLogger, org.xnio.Buffers, .ChannelExceptionHandler, .ChannelListener, .ChannelListeners, .IoUtils, io.undertow.connector.ByteBufferPool, io.undertow.util.Transfer, org.xnio.channels.StreamSinkChannel, .StreamSourceChannel, java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ReadableByteChannel, .WritableByteChannel, java.nio.charset.StandardCharsets

Utility class which holds general useful utility methods which can be used within WebSocket implementations.
Author
Norman Maurer

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
echoFrame(final WebSocketChannel channel, final StreamSourceFrameChannel ws)

Echo back the frame to the sender

public static ByteBuffer

Returns:

buffer The ByteBuffer which was created
fromUtf8String
(CharSequence
The String to convert
utfString
)

Create a ByteBuffer which holds the UTF8 encoded bytes for the given String.

public static <I extends StreamSourceChannel, O extends StreamSinkChannel> void
initiateTransfer(final I
the source channel
source
,
final O
the target channel
sink
,
final ChannelListener<? super I>
the source listener to set and call when the transfer is complete, or null to clear the listener at that time
sourceListener
,
final ChannelListener<? super O>
the target listener to set and call when the transfer is complete, or null to clear the listener at that time
sinkListener
,
final ChannelExceptionHandler<? super I>
the read exception handler to call if an error occurs during a read operation
readExceptionHandler
,
final ChannelExceptionHandler<? super O>
the write exception handler to call if an error occurs during a write operation
writeExceptionHandler
,
ByteBufferPool
the pool from which the transfer buffer should be allocated
pool
)
Deprecated

Initiate a low-copy transfer between two stream channels.

public static String
public static String
public static long
transfer(final ReadableByteChannel source, final long count, final ByteBuffer throughBuffer, final WritableByteChannel sink)

Transfer the data from the source to the sink using the given through buffer to pass data through.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTYback to summary
private static final String EMPTY

Constructor Detail

WebSocketUtilsback to summary
private WebSocketUtils()

Method Detail

echoFrameback to summary
public static void echoFrame(final WebSocketChannel channel, final StreamSourceFrameChannel ws) throws IOException

Echo back the frame to the sender

fromUtf8Stringback to summary
public static ByteBuffer fromUtf8String(CharSequence utfString)

Create a ByteBuffer which holds the UTF8 encoded bytes for the given String.

Parameters
utfString:CharSequence

The String to convert

Returns:ByteBuffer

buffer The ByteBuffer which was created

initiateTransferback to summary
public static <I extends StreamSourceChannel, O extends StreamSinkChannel> void initiateTransfer(final I source, final O sink, final ChannelListener<? super I> sourceListener, final ChannelListener<? super O> sinkListener, final ChannelExceptionHandler<? super I> readExceptionHandler, final ChannelExceptionHandler<? super O> writeExceptionHandler, ByteBufferPool pool)

Deprecated

Initiate a low-copy transfer between two stream channels. The pool should be a direct buffer pool for best performance.

Parameters
source:I

the source channel

sink:O

the target channel

sourceListener:ChannelListener<? super I>

the source listener to set and call when the transfer is complete, or null to clear the listener at that time

sinkListener:ChannelListener<? super O>

the target listener to set and call when the transfer is complete, or null to clear the listener at that time

readExceptionHandler:ChannelExceptionHandler<? super I>

the read exception handler to call if an error occurs during a read operation

writeExceptionHandler:ChannelExceptionHandler<? super O>

the write exception handler to call if an error occurs during a write operation

pool:ByteBufferPool

the pool from which the transfer buffer should be allocated

Annotations
@Deprecated
toUtf8Stringback to summary
public static String toUtf8String(ByteBuffer buffer)
toUtf8Stringback to summary
public static String toUtf8String(ByteBuffer... buffers)
transferback to summary
public static long transfer(final ReadableByteChannel source, final long count, final ByteBuffer throughBuffer, final WritableByteChannel sink) throws IOException

Transfer the data from the source to the sink using the given through buffer to pass data through.