use of io.vertx.core.parsetools.RecordParser in project vert.x by eclipse.
the class RecordParserExamples method example1.
public void example1() {
final RecordParser parser = RecordParser.newDelimited("\n", h -> {
System.out.println(h.toString());
});
parser.handle(Buffer.buffer("HELLO\nHOW ARE Y"));
parser.handle(Buffer.buffer("OU?\nI AM"));
parser.handle(Buffer.buffer("DOING OK"));
parser.handle(Buffer.buffer("\n"));
}
use of io.vertx.core.parsetools.RecordParser in project vert.x by eclipse.
the class RecordParserTest method testIllegalArguments.
@Test
public void testIllegalArguments() throws Exception {
assertNullPointerException(() -> RecordParser.newDelimited((Buffer) null, handler -> {
}));
assertNullPointerException(() -> RecordParser.newDelimited((String) null, handler -> {
}));
RecordParser parser = RecordParser.newDelimited("", handler -> {
});
assertNullPointerException(() -> parser.setOutput(null));
assertNullPointerException(() -> parser.delimitedMode((Buffer) null));
assertNullPointerException(() -> parser.delimitedMode((String) null));
}
use of io.vertx.core.parsetools.RecordParser in project vert.x by eclipse.
the class RecordParserTest method doTestDelimited.
private void doTestDelimited(final Buffer input, Buffer delim, Integer[] chunkSizes, final Buffer... expected) {
final Buffer[] results = new Buffer[expected.length];
Handler<Buffer> out = new Handler<Buffer>() {
int pos;
public void handle(Buffer buff) {
results[pos++] = buff;
}
};
RecordParser parser = RecordParser.newDelimited(delim, out);
feedChunks(input, parser, chunkSizes);
checkResults(expected, results);
}
use of io.vertx.core.parsetools.RecordParser in project vert.x by eclipse.
the class RecordParserTest method testMixed.
@Test
public /*
Test mixture of fixed and delimited
*/
void testMixed() {
final int lines = 8;
final List<Object> types = new ArrayList<Object>();
class MyHandler implements Handler<Buffer> {
RecordParser parser = RecordParser.newFixed(10, this);
int pos;
public void handle(Buffer buff) {
if (pos < lines) {
Object type = types.get(pos);
if (type instanceof byte[]) {
byte[] bytes = (byte[]) type;
parser.delimitedMode(Buffer.buffer(bytes));
} else {
int length = (Integer) type;
parser.fixedSizeMode(length);
}
}
}
}
MyHandler out = new MyHandler();
Buffer[] expected = new Buffer[lines];
Buffer input = Buffer.buffer(100);
expected[0] = TestUtils.randomBuffer(10);
input.appendBuffer(expected[0]);
types.add(expected[0].length());
expected[1] = TestUtils.randomBuffer(100);
input.appendBuffer(expected[1]);
types.add(expected[1].length());
byte[] delim = new byte[] { 23, -120, 100, 3 };
expected[2] = TestUtils.randomBuffer(50, true, delim[0]);
input.appendBuffer(expected[2]);
types.add(delim);
input.appendBuffer(Buffer.buffer(delim));
expected[3] = TestUtils.randomBuffer(1000);
input.appendBuffer(expected[3]);
types.add(expected[3].length());
expected[4] = TestUtils.randomBuffer(230, true, delim[0]);
input.appendBuffer(expected[4]);
types.add(delim);
input.appendBuffer(Buffer.buffer(delim));
delim = new byte[] { 17 };
expected[5] = TestUtils.randomBuffer(341, true, delim[0]);
input.appendBuffer(expected[5]);
types.add(delim);
input.appendBuffer(Buffer.buffer(delim));
delim = new byte[] { 54, -32, 0 };
expected[6] = TestUtils.randomBuffer(1234, true, delim[0]);
input.appendBuffer(expected[6]);
types.add(delim);
input.appendBuffer(Buffer.buffer(delim));
expected[7] = TestUtils.randomBuffer(100);
input.appendBuffer(expected[7]);
types.add(expected[7].length());
feedChunks(input, out.parser, new Integer[] { 50, 10, 3 });
}
Aggregations