private static int readToBufferUntil(
			byte[] bytes, int from, int to, int maxOffset,
			StringBuilder buffer, byte delimiter)
	throws IOException {
		int i = from;
		while ((i < to) && (bytes[i] != delimiter)
				// The reserved characters 0x00 (NUL), 0x02 (STX),
				// 0x03 (ETX), 0x09 (TAB) are not allowed in any parameter
				&& (bytes[i] != NUL) && (bytes[i] != STX)
				&& (bytes[i] != ETX) && (bytes[i] != TAB)) {
			buffer.append((char) bytes[i]);
			i++;
			if ((maxOffset > 0) && ((i - from) > maxOffset)) {
				throw new IOException(
						"Expecting 0x" + Integer.toHexString(delimiter)
						+ " within " + maxOffset + " byte(s), " +
								"but got 0x" + Integer.toHexString(bytes[i - 1]));
			}
		}
		if (bytes[i] != delimiter) {
			throw new IOException(
					"Expecting 0x" + Integer.toHexString(delimiter)
					+ " but got 0x" + Integer.toHexString(bytes[i]));
		} else {
			i++;
		}
		return i;
	}