/** * Merge byte array1 with byte array2, and write to output byte array. It * doesn't hurt original pcap dump byte arrays. * * @param baos * the baos * @param pcaps * the pcaps * * @throws IOException * if there are no source byte arrays, have no read and/or write * permissions, or anything else. */ public static void merge(ByteArrayOutputStream baos, byte[]... pcaps) // $codepro.audit.disable // overloadedMethods throws IOException { merge(baos, Arrays.asList(pcaps)); }
/** * Gets the pcaps. * * @return the pcaps * @throws IOException * Signals that an I/O exception has occurred. */ public byte[] getPcaps() throws IOException { if (pcaps.size() == 1) { return pcaps.get(0); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); PcapMerger.merge(baos, pcaps); return baos.toByteArray(); }
/** * The main method. * * @param args * the arguments * * @throws IOException * Signals that an I/O exception has occurred. */ public static void main(String[] args) throws IOException { byte[] b1 = FileUtils.readFileToByteArray(new File( "/Users/sheetal/Downloads/constructedTcpDump.1.pcap")); byte[] b2 = FileUtils.readFileToByteArray(new File( "/Users/sheetal/Downloads/constructedTcpDump.2.pcap")); byte[] b3 = FileUtils.readFileToByteArray(new File( "/Users/sheetal/Downloads/constructedTcpDump.3.pcap")); ByteArrayOutputStream boas = new ByteArrayOutputStream(); // $codepro.audit.disable // closeWhereCreated PcapMerger.merge(boas, b1, b2, b3); FileUtils.writeByteArrayToFile(new File( "/Users/sheetal/Downloads/constructedTcpDump.automerged.1.2.pcap"), boas.toByteArray(), false); } }
PcapMerger.merge(baos, pcaps); byte[] response = baos.toByteArray(); return response;