Here you can find the source of getStringFromBuffer(ByteBuffer buf, int len)
public static String getStringFromBuffer(ByteBuffer buf, int len)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static String getStringFromBuffer(ByteBuffer buf, int len) { byte[] bytes = new byte[len]; buf.get(bytes);//from w ww . j ava2 s . co m return esc0(new String(bytes)); } public static String esc0(String s) { if (s == null || s.length() == 0) { s = ""; return s; } else { int i = s.indexOf('\0'); if (i > 0) s = s.substring(0, i); else s = s.replaceAll("\0", ""); } return s; } }