message = new String(data);
messageString = new String(data);
    public boolean read(ByteBuffer buffer) throws MessageParseException {        for (;;) {            try {                if (state == SEEKING_HEADER) {                    if (buffer.remaining() < headerBytes.length) {                        break;                    }                    // TODO PERFORMANCE this can be optimized in recognizer                    messageStartPosition = indexOf(buffer, buffer.position(), headerBytes);                    if (messageStartPosition == -1) {                        throw new MessageParseException("inconsistent header recognization"                                + " between message recognizer and parser");                    }                    log.debug("found header");                    position = messageStartPosition + headerBytes.length;                    state = PARSING_LENGTH;                }                if (state == PARSING_LENGTH) {                    if (position >= buffer.limit()) {                        break;                    }                    bodyLength = 0;                    byte ch = buffer.get(position++);                    while (Character.isDigit((char) ch)) {                        bodyLength = bodyLength * 10 + (ch - '0');                        if (position < buffer.limit()) {                            ch = buffer.get(position++);                        } else {                            break;                        }                    }                    if (position >= buffer.limit()) {                        break;                    }                    if (ch != '\001') {                        handleError(buffer, "Error in message length", false);                        break;                    }                    bodyStartPosition = position;                    state = READING_BODY;                    log.debug("reading body, length = " + bodyLength);                }                if (state == READING_BODY) {                    if ((buffer.limit() - position) < bodyLength) {                        break;                    }                    position += bodyLength;                    state = PARSING_CHECKSUM;                }                if (state == PARSING_CHECKSUM) {                    if (startsWith(buffer, position, checksumBytes)) {                        log.debug("parsing checksum");                        position += checksumBytes.length;                    } else {                        if (position + checksumBytes.length < buffer.limit()) {                            handleError(buffer, "did not find checksum field, bad length?",                                    isLogon(buffer, messageStartPosition));                            if (buffer.remaining() > 0) {                                continue;                            } else {                                break;                            }                        } else {                            break;                        }                    }                    byte[] data = new byte[position - messageStartPosition];                    buffer.position(messageStartPosition);                    buffer.get(data);                    message = new String(data);                    if (log.isTraceEnabled()) {                        log.trace("extracted message: " + message + ", remaining="                                + buffer.remaining());                    }                    return true;                }            } catch (Throwable t) {                state = SEEKING_HEADER;                throw new MessageParseException(t);            }        }        return false;    }