Here you can find the source of getByteBufferFromUTF8(String str)
public static ByteBuffer getByteBufferFromUTF8(String str)
//package com.java2s; //License from project: Open Source License import java.nio.*; import java.nio.charset.*; public class Main { public static ByteBuffer getByteBufferFromUTF8(String str) { Charset charset = Charset.forName("UTF-8"); CharsetEncoder encoder = charset.newEncoder(); try {/*from w ww.j a v a2 s . c o m*/ return encoder.encode(CharBuffer.wrap(str)); } catch (Exception e) { e.printStackTrace(); } return null; } }