Class BufferUtils


  • public final class BufferUtils
    extends java.lang.Object
    Internal utilities for Buffers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static io.netty.buffer.ByteBuf extractByteBufOrCreate​(Buffer buffer)
      Converts the passed buffer to ByteBuf, creating a new ByteBuf instance if required.
      static io.netty.buffer.ByteBufAllocator getByteBufAllocator​(BufferAllocator allocator)
      Returns the ByteBufAllocator taking the BufferAllocator into account.
      static int maxUtf8Bytes​(java.lang.CharSequence data)
      Calculate the max bytes length of UTF8 character sequence.
      static Buffer newBufferFrom​(io.netty.buffer.ByteBuf buffer)
      Return a Buffer for the given ByteBuf.
      static io.netty.buffer.ByteBuf toByteBuf​(Buffer buffer)
      Return a ByteBuf for the given buffer.
      static io.netty.buffer.ByteBuf toByteBufNoThrow​(Buffer buffer)
      Converts the passed buffer to ByteBuf, or returns null if not possible.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toByteBuf

        public static io.netty.buffer.ByteBuf toByteBuf​(Buffer buffer)
        Return a ByteBuf for the given buffer.
        Parameters:
        buffer - the buffer.
        Returns:
        a ByteBuf.
      • extractByteBufOrCreate

        public static io.netty.buffer.ByteBuf extractByteBufOrCreate​(Buffer buffer)
        Converts the passed buffer to ByteBuf, creating a new ByteBuf instance if required.
        Parameters:
        buffer - the buffer.
        Returns:
        a ByteBuf.
      • toByteBufNoThrow

        @Nullable
        public static io.netty.buffer.ByteBuf toByteBufNoThrow​(Buffer buffer)
        Converts the passed buffer to ByteBuf, or returns null if not possible.
        Parameters:
        buffer - The Buffer to convert.
        Returns:
        a ByteBuf equivalent of buffer, or null if no equivalent can be found.
      • getByteBufAllocator

        public static io.netty.buffer.ByteBufAllocator getByteBufAllocator​(BufferAllocator allocator)
        Returns the ByteBufAllocator taking the BufferAllocator into account.
        Parameters:
        allocator - the BufferAllocator that is used.
        Returns:
        the ByteBufAllocator to use.
      • newBufferFrom

        public static Buffer newBufferFrom​(io.netty.buffer.ByteBuf buffer)
        Return a Buffer for the given ByteBuf.
        Parameters:
        buffer - the buffer to wrap.
        Returns:
        the created buffer.
      • maxUtf8Bytes

        public static int maxUtf8Bytes​(java.lang.CharSequence data)
        Calculate the max bytes length of UTF8 character sequence.
        Parameters:
        data - the data to be encoded in UTF8.
        Returns:
        max bytes length of UTF8 character sequence.