Here you can find the source of toString(ByteBuffer b, String separator)
public static final String toString(ByteBuffer b, String separator)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.nio.ByteBuffer; public class Main { public static final String toString(ByteBuffer b, String separator) { StringBuilder s = new StringBuilder(); for (int i = b.position(); i < b.limit(); i++) { if (i > b.position()) s.append(separator);//from w ww . j a va 2s . c o m byte c = b.get(i); if (c >= 0) s.append(c); else s.append(256 + c); } return s.toString(); } }