code: protected final ByteBuf newDirectBuffer(ByteBuf buf) {
          final int readableBytes = buf.readableBytes();
          if (readableBytes == 0) {
              ReferenceCountUtil.safeRelease(buf);
              return Unpooled.EMPTY_BUFFER;
          }
  
          final ByteBufAllocator alloc = alloc();
          if (alloc.isDirectBufferPooled()) {
              ByteBuf directBuf = alloc.directBuffer(readableBytes);
              directBuf.writeBytes(buf, buf.readerIndex(), readableBytes);
              ReferenceCountUtil.safeRelease(buf);
              return directBuf;
          }
  
          final ByteBuf directBuf = ByteBufUtil.threadLocalDirectBuffer();
          if (directBuf != null) {
              directBuf.writeBytes(buf, buf.readerIndex(), readableBytes);
              ReferenceCountUtil.safeRelease(buf);
              return directBuf;
          }
  
          // Allocating and deallocating an unpooled direct buffer is very expensive; give up.
          return buf;
      }
docs: Returns an off-heap copy of the specified {@link ByteBuf}, and releases the original one.
  Note that this method does not create an off-heap copy if the allocation / deallocation cost is too high,
  but just returns the original {@link ByteBuf}..