Here you can find the source of getStringFromByteBuffer(ByteBuffer bb)
Parameter | Description |
---|---|
bb | ByteBuffer to be converted to a string |
public static String getStringFromByteBuffer(ByteBuffer bb)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { /**/* w w w.j a va2s. c o m*/ * Returns a String representation of a ByteBuffer. * @param bb ByteBuffer to be converted to a string * @return String message */ public static String getStringFromByteBuffer(ByteBuffer bb) { StringBuilder message = new StringBuilder(); int bytes; while (true) { try { bytes = bb.get(); // format the product of two bytes and a bitwise AND with 0xFF message.append("\\x" + String.format("%02x", bytes & 0xff)); } catch (Exception e) { break; } } return message.toString(); } }