Here you can find the source of getByteBufferAsString(ByteBuffer buff)
public static String getByteBufferAsString(ByteBuffer buff)
//package com.java2s; /*//from w w w .ja v a 2 s . c om * Copyright (C) Mellanox Technologies Ltd. 2001-2017. ALL RIGHTS RESERVED. * See file LICENSE for terms. */ import java.nio.ByteBuffer; import java.nio.charset.Charset; public class Main { public static String getByteBufferAsString(ByteBuffer buff) { int pos = buff.position(); byte[] tmpBuff = new byte[buff.remaining()]; buff.get(tmpBuff); buff.position(pos); return new String(tmpBuff, Charset.forName("US-ASCII")); } }