use of loghub.netflow.NetflowPacket in project LogHub by fbacchella.
the class PacketsTest method testParse.
@Test
public void testParse() {
final List<NetflowPacket> packets = new ArrayList<>();
Arrays.stream(captures).map(i -> {
logger.debug(i + ": ");
return i;
}).map(i -> "/netflow/packets/" + i).map(i -> getClass().getResourceAsStream(i)).filter(i -> i != null).map(i -> {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8 * 1024];
for (int length; (length = i.read(buffer)) != -1; ) {
out.write(buffer, 0, length);
}
return out;
} catch (Exception e) {
Assert.fail(e.getMessage());
return null;
}
}).filter(i -> i != null).map(i -> Unpooled.wrappedBuffer(i.toByteArray())).forEach(i -> {
try {
while (i.isReadable()) {
packets.add(PacketFactory.parsePacket(InetAddress.getLocalHost(), i));
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
});
packets.forEach(i -> {
logger.debug(" {} {} {} {} {}\n", i.getVersion(), i.getLength(), i.getSequenceNumber(), i.getExportTime(), i.getId());
i.getRecords().forEach(j -> logger.debug(" {}\n", j));
});
;
}
Aggregations