Here you can find the source of readCharsUTF8(ByteBuffer bb, int length)
public static String readCharsUTF8(ByteBuffer bb, int length) throws IOException
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.nio.ByteBuffer; public class Main { private static final String CHARSET_UTF8 = "UTF-8"; public static String readCharsUTF8(ByteBuffer bb, int length) throws IOException { byte[] b = new byte[length]; bb.get(b);/*from w w w .j a v a 2s . c o m*/ // lookup null character for string termination int strLength = 0; for (int i = 0; i < b.length; i++) { if (b[i] == 0) { break; } strLength++; } return new String(b, 0, strLength, CHARSET_UTF8); } }