code: public static ByteBuffer toByteBuffer(String s) {
          ByteBuffer buffer = ByteBuffer.allocateDirect(s.length());
          buffer.put(s.getBytes(UTF_8));
          buffer.flip();
          return buffer;
      }
docs: convert String to ByteBuffer
  @param s string to be converted
  @return ByteBuffer the result ByteBuffer