@Test
public void testReadMessages() throws Exception {
String path = TMP + "/testReadMessages";
ChronicleTools.deleteOnExit(path);
IndexedChronicle chronicle = new IndexedChronicle(path);
Excerpt excerpt = chronicle.createExcerpt();
FixSocketReader fsr = new FixSocketReader(null, excerpt) {
final byte[] bytes = S.getBytes("US-ASCII");
int start = 0;
@Override
protected void readMoreData(@NotNull ByteBuffer buffer) throws IOException {
int end = Math.min(bytes.length, start + 256);
buffer.put(bytes, start, end - start);
start = end;
if (end == bytes.length)
close();
}
};
FixDecoder fd = new FixDecoder(fsr);
FixDecodeListener listener = new FixDecodeListener() {
@Override
public void onField(int fid, @NotNull Excerpt value) {
String text = value.parseUTF(StopCharTesters.FIX_TEXT);
System.out.println("\t" + fid + "=" + text);
}
@Override
public void onEndOfMessage() {
System.out.println("EOM");
}
@Override
public void onEndOfBatch() {
System.out.println("EOB");
}
};
while (!fsr.isClosed()) {
fd.readMessages(listener);
}
excerpt.index(-1);
int count = 0;
while (excerpt.nextIndex()) {
int length = (int) excerpt.readStopBit();
String fix = ChronicleTools.asString(excerpt, excerpt.position(), length);
assertTrue(fix.startsWith("8=FIX"));
assertTrue(fix.endsWith(".")); // ^A is replaced with .
assertEquals(8, fix.length() - fix.lastIndexOf(".10="));
int pos = -1;
while ((pos = fix.indexOf(".10=", pos + 1)) > 0)