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