public static ByteBuffer createByteBuffer(String data) {
        try {
            byte[] bytes = data.getBytes("UTF-8");
            ByteBuffer bb = createByteBuffer(bytes.length);
            bb.put(bytes);
            bb.flip();
            return bb;
        } catch (UnsupportedEncodingException ex) {
            throw new UnsupportedOperationException(ex);
        }
    }
Create a new ByteBuffer of an appropriate size to hold the specified
number of ints only if the given buffer if not already the right size.

@param buf
           the buffer to first check and rewind
@param size
           number of bytes that need to be held by the newly created
           buffer
@return the requested new IntBuffer
jme3-core/src/main/java/com/jme3/util/BufferUtils.java