@Test public void shouldStopReadingWhenTheMessageIsNotLogon() { final byte[] newOrderSingleMsg = FixMessageUtil.getNewOrderSingle(); final InOrder inOrder = BDDMockito.inOrder(fixTagHandler); given(fixTagHandler.isFinished()).willReturn(false).willReturn(false).willReturn(true); final FixTagParser parser = new FixTagParser(fixTagHandler); parser.parse(newOrderSingleMsg, 0, newOrderSingleMsg.length, true); inOrder.verify(fixTagHandler).messageStart(); inOrder.verify(fixTagHandler).onTag(8, newOrderSingleMsg, 2, 7); inOrder.verify(fixTagHandler, times(1)).isFinished(); inOrder.verify(fixTagHandler).onTag(9, newOrderSingleMsg, 12, 3); inOrder.verify(fixTagHandler, times(1)).isFinished(); inOrder.verify(fixTagHandler).onTag(35, newOrderSingleMsg, 19, 1); inOrder.verify(fixTagHandler, times(1)).isFinished(); inOrder.verify(fixTagHandler).messageEnd(); }
public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } FixTagParser(final FixTagHandler fixTagHandler);  FixTagParser(final FixTagHandler fixTagHandler, final byte[] lineSeparators); }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } FixTagParser(final FixTagHandler fixTagHandler);  FixTagParser(final FixTagHandler fixTagHandler, final byte[] lineSeparators); boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure); }
FixTagParser { public boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure) { fixTagHandler.messageStart(); int tagStart = offset; int equalsIndex = -1; for (int i = 0; i < length; i++) { int index = i + offset; if (ASCII_EQUALS == message[index]) { equalsIndex = index; } if (containsLineSeparator(message[index])) { if (-1 != equalsIndex) { if (!ByteUtil.isInteger(message, tagStart, equalsIndex - tagStart)) { if (throwExceptionOnParseFailure) { raiseException("Invalid tag id", message, offset, length, tagStart, equalsIndex); } return false; } int tagIdentity = ByteUtil.readIntFromAscii(message, tagStart, equalsIndex - tagStart); final int tagValueOffset = equalsIndex + 1; final int tagValueLength = index - tagValueOffset; fixTagHandler.onTag(tagIdentity, message, tagValueOffset, tagValueLength); if (fixTagHandler.isFinished()) { break; } } tagStart = index + 1; equalsIndex = -1; } } fixTagHandler.messageEnd(); return true; } FixTagParser(final FixTagHandler fixTagHandler);  FixTagParser(final FixTagHandler fixTagHandler, final byte[] lineSeparators); boolean parse(final byte[] message, final int offset, final int length, final boolean throwExceptionOnParseFailure); static final byte SOH; }