b = readByte(istream);
if (b != '9')
{
throw new MalformedMessageException("Tag 9 does not follow tag 8");
}
messageBuffer[messageBufferIndex++] = b;
messageBuffer[messageBufferIndex++] = (byte) istream.read();
byte[] messageLengthBuffer = new byte[16];
int messageLengthBufferOffset = 0;
while ((b = readByte(istream)) != '\1')
{
messageBuffer[messageBufferIndex++] = b;
messageLengthBuffer[messageLengthBufferOffset++] = b;
}
messageLengthBuffer[messageLengthBufferOffset++] = '\1';
messageBuffer[messageBufferIndex++] = '\1';
final String s = new String(messageLengthBuffer).trim();
final int messageLength = Integer.parseInt(s);
if (messageLength > maxMessageBuffer)
{
throw new MalformedMessageException("BodyLength is too big, " + messageLength + " > " + maxMessageBuffer);
}
readByte(istream, messageBuffer, messageBufferIndex, messageLength);
messageBufferIndex += messageLength;