Class WebSocketUtils

java.lang.Object
io.undertow.websockets.core.WebSocketUtils

public final class WebSocketUtils extends Object
Utility class which holds general useful utility methods which can be used within WebSocket implementations.
Author:
Norman Maurer
  • Method Details

    • fromUtf8String

      public static ByteBuffer fromUtf8String(CharSequence utfString)
      Create a ByteBuffer which holds the UTF8 encoded bytes for the given String.
      Parameters:
      utfString - The String to convert
      Returns:
      buffer The ByteBuffer which was created
    • toUtf8String

      public static String toUtf8String(ByteBuffer buffer)
    • toUtf8String

      public static String toUtf8String(ByteBuffer... buffers)
    • transfer

      public static long transfer(ReadableByteChannel source, long count, ByteBuffer throughBuffer, WritableByteChannel sink) throws IOException
      Transfer the data from the source to the sink using the given through buffer to pass data through.
      Throws:
      IOException
    • echoFrame

      public static void echoFrame(WebSocketChannel channel, StreamSourceFrameChannel ws) throws IOException
      Echo back the frame to the sender
      Throws:
      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 channel
      sink - the target channel
      sourceListener - the source listener to set and call when the transfer is complete, or null to clear the listener at that time
      sinkListener - the target listener to set and call when the transfer is complete, or null to clear the listener at that time
      readExceptionHandler - the read exception handler to call if an error occurs during a read operation
      writeExceptionHandler - the write exception handler to call if an error occurs during a write operation
      pool - the pool from which the transfer buffer should be allocated