public static String readString(ByteBuffer buffer, int numBytes, int maxLength) throws NhzException.NotValidException { if (numBytes > 3 * maxLength) { throw new NhzException.NotValidException("Max parameter length exceeded"); } byte[] bytes = new byte[numBytes]; buffer.get(bytes); return Convert.toString(bytes); }