try { byte[] bytes = string.getBytes("UTF-8"); buffer.put(bytes); buffer.put((byte) 0); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e);
final byte[] bytes = data.getBytes(Charset.forName("UTF-8")); return ByteBuffer.wrap(bytes);