/** * Write packet. * * @param is * the is * @param os * the os * * @throws IOException * Signals that an I/O exception has occurred. */ private static void writePacket(PcapByteInputStream is, PcapByteOutputStream os) throws IOException { PcapPacket packet = null; try { while (true) { packet = is.getPacket(); if (packet == null) { break; } os.write(packet); } } catch (EOFException e) { //LOG.debug("Ignorable exception in writePacket", e); } }
/** * Close input. * * @param is * the is */ private static void closeInput(PcapByteInputStream is) { if (is == null) { return; } try { is.close(); // $codepro.audit.disable closeInFinally } catch (IOException e) { LOG.error("Failed to close input stream", e); } }
/** * Opens pcap file input stream. * * @param pcap * the byte array to be read * * @throws IOException * Signals that an I/O exception has occurred. */ public PcapByteInputStream(byte[] pcap) throws IOException { is = new DataInputStream(new ByteArrayInputStream(pcap)); // $codepro.audit.disable // closeWhereCreated readGlobalHeader(); }
/** * Read packet. * * @param magicNumber * the magic number * @return the pcap packet * @throws IOException Signals that an I/O exception * has occurred. * @throws EOFException the EOF exception * @throws IOException * Signals that an I/O exception has occurred. */ private PcapPacket readPacket(int magicNumber) throws IOException { PacketHeader packetHeader = readPacketHeader(magicNumber); Buffer packetData = readPacketData(packetHeader.getInclLen()); return new PcapPacket(packetHeader, packetData); }
PcapByteInputStream pcapIs = new PcapByteInputStream(unsortedBytes); PcapByteOutputStream pcapOs = new PcapByteOutputStream(baos, pcapIs.getGlobalHeader()); PcapPacket packet; ArrayList<PcapPacket> packetList = new ArrayList<PcapPacket>(); packet = pcapIs.getPacket(); if (packet == null) break;
int i = 1; for (byte[] pcap : pcaps) { is = new PcapByteInputStream(pcap); if (i == 1) { os = new PcapByteOutputStream(unsortedBaos, is.getGlobalHeader());
/** * Reads a packet from pcap byte array. * * @return the packet throws IOException the stream has been closed and the * contained input stream does not support reading after close, or * another I/O error occurs. * @throws IOException Signals that an I/O * exception has occurred. * @see * org.krakenapps.pcap.PcapInputStream#getPacket() * @throws IOException * Signals that an I/O exception has occurred. */ public PcapPacket getPacket() throws IOException { return readPacket(globalHeader.getMagicNumber()); }
List<PacketInfo> packetInfoList = new ArrayList<PacketInfo>(); PcapByteInputStream pcapByteInputStream = new PcapByteInputStream(tcpdump); GlobalHeader globalHeader = pcapByteInputStream.getGlobalHeader(); while (true) { try PcapPacket packet = pcapByteInputStream.getPacket();
List<PacketInfo> packetInfoList = new ArrayList<PacketInfo>(); PcapByteInputStream pcapByteInputStream = new PcapByteInputStream(pcap); GlobalHeader globalHeader = pcapByteInputStream.getGlobalHeader(); while (true) { try PcapPacket packet = pcapByteInputStream.getPacket();