Package io.undertow.websockets.core
Class WebSocketUtils
- java.lang.Object
-
- io.undertow.websockets.core.WebSocketUtils
-
public final class WebSocketUtils extends java.lang.Object
Utility class which holds general useful utility methods which can be used within WebSocket implementations.- Author:
- Norman Maurer
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
echoFrame(WebSocketChannel channel, StreamSourceFrameChannel ws)
Echo back the frame to the senderstatic java.nio.ByteBuffer
fromUtf8String(java.lang.CharSequence utfString)
Create aByteBuffer
which holds the UTF8 encoded bytes for the givenString
.static <I extends org.xnio.channels.StreamSourceChannel,O extends org.xnio.channels.StreamSinkChannel>
voidinitiateTransfer(I source, O sink, org.xnio.ChannelListener<? super I> sourceListener, org.xnio.ChannelListener<? super O> sinkListener, org.xnio.ChannelExceptionHandler<? super I> readExceptionHandler, org.xnio.ChannelExceptionHandler<? super O> writeExceptionHandler, ByteBufferPool pool)
Deprecated.static java.lang.String
toUtf8String(java.nio.ByteBuffer buffer)
static java.lang.String
toUtf8String(java.nio.ByteBuffer... buffers)
static long
transfer(java.nio.channels.ReadableByteChannel source, long count, java.nio.ByteBuffer throughBuffer, java.nio.channels.WritableByteChannel sink)
Transfer the data from the source to the sink using the given through buffer to pass data through.
-
-
-
Method Detail
-
fromUtf8String
public static java.nio.ByteBuffer fromUtf8String(java.lang.CharSequence utfString)
Create aByteBuffer
which holds the UTF8 encoded bytes for the givenString
.- Parameters:
utfString
- TheString
to convert- Returns:
- buffer The
ByteBuffer
which was created
-
toUtf8String
public static java.lang.String toUtf8String(java.nio.ByteBuffer buffer)
-
toUtf8String
public static java.lang.String toUtf8String(java.nio.ByteBuffer... buffers)
-
transfer
public static long transfer(java.nio.channels.ReadableByteChannel source, long count, java.nio.ByteBuffer throughBuffer, java.nio.channels.WritableByteChannel sink) throws java.io.IOException
Transfer the data from the source to the sink using the given through buffer to pass data through.- Throws:
java.io.IOException
-
echoFrame
public static void echoFrame(WebSocketChannel channel, StreamSourceFrameChannel ws) throws java.io.IOException
Echo back the frame to the sender- Throws:
java.io.IOException
-
initiateTransfer
@Deprecated public static <I extends org.xnio.channels.StreamSourceChannel,O extends org.xnio.channels.StreamSinkChannel> void initiateTransfer(I source, O sink, org.xnio.ChannelListener<? super I> sourceListener, org.xnio.ChannelListener<? super O> sinkListener, org.xnio.ChannelExceptionHandler<? super I> readExceptionHandler, org.xnio.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
- the source channelsink
- the target channelsourceListener
- the source listener to set and call when the transfer is complete, ornull
to clear the listener at that timesinkListener
- the target listener to set and call when the transfer is complete, ornull
to clear the listener at that timereadExceptionHandler
- the read exception handler to call if an error occurs during a read operationwriteExceptionHandler
- the write exception handler to call if an error occurs during a write operationpool
- the pool from which the transfer buffer should be allocated
-
-