Here you can find the source of bytesToString(byte[] buffer)
private static String bytesToString(byte[] buffer)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { private static String bytesToString(byte[] buffer) { byte[] bytes = null; for (int i = 0; i < buffer.length; i++) { if (buffer[i] == '\0') { bytes = Arrays.copyOfRange(buffer, 0, i); break; }/*from ww w . j av a2s . co m*/ } return new String(bytes); } }