Here you can find the source of toText(@Nonnull byte[] bytes)
@Nonnull public static String toText(@Nonnull byte[] bytes)
//package com.java2s; //License from project: Apache License import com.google.common.primitives.UnsignedBytes; import java.nio.ByteBuffer; import java.util.Arrays; import javax.annotation.Nonnull; public class Main { @Nonnull public static String toText(@Nonnull byte[] bytes) { StringBuilder buf = new StringBuilder(); for (byte b : bytes) { if (Character.isValidCodePoint(b)) buf.append((char) b); else/*from ww w . ja v a2 s .c om*/ buf.append("\\x").append(UnsignedBytes.toString(b, 16)); } return buf.toString(); } @Nonnull public static String toString(@Nonnull ByteBuffer buf, int len) { byte[] b = new byte[Math.min(buf.remaining(), len)]; for (int i = 0; i < b.length; i++) b[i] = buf.get(buf.position() + i); return "[" + Arrays.toString(b) + "...(" + buf.remaining() + " bytes)]"; } }