Pcap { public void loop(final PacketHandler callback) throws IOException, FramingException { final ByteOrder byteOrder = this.header.getByteOrder(); final PcapFramer framer = new PcapFramer(this.header, this.framerManager); int count = 1; Packet packet = null; boolean processNext = true; while ((packet = framer.frame(null, this.buffer)) != null && processNext) { try { final long time = packet.getArrivalTime(); this.framerManager.tick(time); if (this.filter == null) { processNext = callback.nextPacket(packet); } else if (this.filter != null && this.filter.accept(packet)) { processNext = callback.nextPacket(packet); } } catch (final FilterException e) { System.err.println("WARN: the filter complained about the last frame. Msg (if any) - " + e.getMessage()); } } } private  Pcap(final PcapGlobalHeader header, final Buffer buffer); void setFilter(final String expression); void loop(final PacketHandler callback); PcapOutputStream createOutputStream(final OutputStream out); static Pcap openStream(final InputStream is); static Pcap openStream(final InputStream is, final int bufferCapacity); static Pcap openStream(final File file); static Pcap openStream(final String file); void close(); PcapGlobalHeader getPcapHeader();  }
@Test public void testLoop() throws Exception { final InputStream stream = PktsTestBase.class.getResourceAsStream("sipp.pcap"); final Pcap pcap = Pcap.openStream(stream); final FrameHandlerImpl handler = new FrameHandlerImpl(); pcap.loop(handler); pcap.close(); assertThat(handler.count, is(30)); }