dan-s1 commented on code in PR #8691:
URL: https://github.com/apache/nifi/pull/8691#discussion_r1608585813


##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,151 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+    private ByteBufferInterface io;
+    private final Logger logger = LoggerFactory.getLogger(Header.class);
+
+    public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root;
+        this.io = io;
+
+        try {
+            read();
+        } catch (ByteBufferInterface.ValidationNotEqualError e) {
+            this.logger.error("PCAP file header could not be parsed due to ", 
e);
+        }
+    }
+
+    public Header(byte[] magicNumber, int versionMajor, int versionMinor, int 
thiszone, long sigfigs, long snaplen,
+            long network) {
+
+        this.magicNumber = magicNumber;
+        this.versionMajor = versionMajor;
+        this.versionMinor = versionMinor;
+        this.thiszone = thiszone;
+        this.sigfigs = sigfigs;
+        this.snaplen = snaplen;
+        this.network = network;
+    }
+
+    public ByteBufferInterface io() {
+        return io;
+    }
+
+    private void read()
+            throws ByteBufferInterface.ValidationNotEqualError {
+        this.magicNumber = this.io.readBytes(4);
+        if (this.magicNumber == new byte[] {(byte) 0xd4, (byte) 0xc3, (byte) 
0xb2, (byte) 0xa1 }) {
+            // have to swap the bits
+            this.versionMajor = this.io.readU2be();
+            if (!(versionMajor() == 2)) {
+
+                throw new ByteBufferInterface.ValidationNotEqualError("Packet 
major version is not 2.");
+            }
+            this.versionMinor = this.io.readU2be();
+            this.thiszone = this.io.readS4be();
+            this.sigfigs = this.io.readU4be();
+            this.snaplen = this.io.readU4be();
+            this.network = this.io.readU4be();
+        } else {
+            this.versionMajor = this.io.readU2le();
+            if (!(versionMajor() == 2)) {
+                throw new ByteBufferInterface.ValidationNotEqualError("Packet 
major version is not 2.");
+            }
+            this.versionMinor = this.io.readU2le();
+            this.thiszone = this.io.readS4le();
+            this.sigfigs = this.io.readU4le();
+            this.snaplen = this.io.readU4le();
+            this.network = this.io.readU4le();
+        }

Review Comment:
   Add some spacing between `if` blocks and other assignments
   ```suggestion
           if (this.magicNumber == new byte[] {(byte) 0xd4, (byte) 0xc3, (byte) 
0xb2, (byte) 0xa1 }) {
               // have to swap the bits
               this.versionMajor = this.io.readU2be();
               if (!(versionMajor() == 2)) {
   
                   throw new 
ByteBufferInterface.ValidationNotEqualError("Packet major version is not 2.");
               }
               
               this.versionMinor = this.io.readU2be();
               this.thiszone = this.io.readS4be();
               this.sigfigs = this.io.readU4be();
               this.snaplen = this.io.readU4be();
               this.network = this.io.readU4be();
           } else {
               this.versionMajor = this.io.readU2le();
               if (!(versionMajor() == 2)) {
                   throw new 
ByteBufferInterface.ValidationNotEqualError("Packet major version is not 2.");
               }
               
               this.versionMinor = this.io.readU2le();
               this.thiszone = this.io.readS4le();
               this.sigfigs = this.io.readU4le();
               this.snaplen = this.io.readU4le();
               this.network = this.io.readU4le();
           }
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,151 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+    private ByteBufferInterface io;
+    private final Logger logger = LoggerFactory.getLogger(Header.class);

Review Comment:
   Switch positions and make the logger static final
   ```suggestion
       private static final Logger logger = 
LoggerFactory.getLogger(Header.class);
       private ByteBufferInterface io;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/PCAP.java:
##########
@@ -0,0 +1,161 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](<a 
href="https://www.tcpdump.org/";>...</a>) or
+ * [Wireshark](<a href="https://www.wireshark.org/";>...</a>).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    private ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io) {
+        this(io, null, null);
+    }
+
+    public PCAP(ByteBufferInterface io, Object parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root == null ? this : root;
+        this.io = io;
+        read();
+    }
+
+    public PCAP(Header hdr, List<Packet> packets) {
+        this.hdr = hdr;
+        this.packets = packets;
+    }
+
+    public byte[] readBytesFull() {
+
+        int headerBufferSize = 20 + this.hdr().magicNumber().length;
+        ByteBuffer headerBuffer = ByteBuffer.allocate(headerBufferSize);
+        headerBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        headerBuffer.put(this.hdr().magicNumber());
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMajor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().versionMinor(), 2, 
false));
+        headerBuffer.put(this.readIntToNBytes(this.hdr().thiszone(), 4, 
false));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().sigfigs(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().snaplen(), 4, true));
+        headerBuffer.put(this.readLongToNBytes(this.hdr().network(), 4, true));
+
+        List<byte[]> packetByteArrays = new ArrayList<>();
+
+        int packetBufferSize = 0;
+
+        for (Packet currentPacket : packets) {
+            ByteBuffer currentPacketBytes = ByteBuffer.allocate(16 + 
currentPacket.rawBody().length);
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsSec(), 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.tsUsec(), 4, 
false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.inclLen(), 
4, false));
+            currentPacketBytes.put(readLongToNBytes(currentPacket.origLen(), 
4, false));
+            currentPacketBytes.put(currentPacket.rawBody());
+
+            packetByteArrays.add(currentPacketBytes.array());
+            packetBufferSize += 16 + currentPacket.rawBody().length;
+        }
+
+        ByteBuffer packetBuffer = ByteBuffer.allocate(packetBufferSize);
+        packetBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+        for (byte[] packetByteArray : packetByteArrays) {
+            packetBuffer.put(packetByteArray);
+        }
+
+        ByteBuffer allBytes = ByteBuffer.allocate(headerBufferSize + 
packetBufferSize);
+        allBytes.order(ByteOrder.LITTLE_ENDIAN);
+
+        allBytes.put(headerBuffer.array());
+        allBytes.put(packetBuffer.array());
+
+        return allBytes.array();
+    }
+
+    private byte[] readIntToNBytes(int input, int numberOfBytes, boolean 
isSigned) {
+        byte[] output = new byte[numberOfBytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < numberOfBytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private byte[] readLongToNBytes(long input, int numberOfBytes, boolean 
isSigned) {
+        byte[] output = new byte[numberOfBytes];
+        output[0] = (byte) (input & 0xff);
+        for (int loop = 1; loop < numberOfBytes; loop++) {
+            if (isSigned) {
+                output[loop] = (byte) (input >> (8 * loop));
+            } else {
+                output[loop] = (byte) (input >>> (8 * loop));
+            }
+        }
+        return output;
+    }
+
+    private void read() {
+        this.hdr = new Header(this.io, this, root);
+        this.packets = new ArrayList<>();
+        {
+            while (!this.io.isEof()) {
+                this.packets.add(new Packet(this.io, this, root));
+            }
+        }
+    }
+    private Header hdr;
+    private List<Packet> packets;
+    private PCAP root;
+    private Object parent;

Review Comment:
   Please remove from here and place above after declaration of `private 
ByteBufferInterface io;`
   ```suggestion
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/SplitPCAP.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network.pcap;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.behavior.SideEffectFree;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.flowfile.attributes.FragmentAttributes;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.IntStream;
+
+@SideEffectFree
+@InputRequirement(Requirement.INPUT_REQUIRED)
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark", "TcpDump", "WinDump", "sniffers"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttributes({
+    @WritesAttribute(
+        attribute = SplitPCAP.ERROR_REASON,
+        description = "The reason the flowfile was sent to the failure 
relationship."
+    ),
+    @WritesAttribute(
+        attribute = "fragment.identifier",
+        description = "All split PCAP FlowFiles produced from the same parent 
PCAP FlowFile will have the same randomly generated UUID added for this 
attribute"
+    ),
+    @WritesAttribute(
+        attribute = "fragment.index",
+        description = "A one-up number that indicates the ordering of the 
split PCAP FlowFiles that were created from a single parent PCAP FlowFile"
+    ),
+    @WritesAttribute(
+        attribute = "fragment.count",
+        description = "The number of split PCAP FlowFiles generated from the 
parent PCAP FlowFile"
+    ),
+    @WritesAttribute(
+        attribute = "segment.original.filename ",
+        description = "The filename of the parent PCAP FlowFile"
+    )
+})
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+    public static final String FRAGMENT_ID = 
FragmentAttributes.FRAGMENT_ID.key();
+    public static final String FRAGMENT_INDEX = 
FragmentAttributes.FRAGMENT_INDEX.key();
+    public static final String FRAGMENT_COUNT = 
FragmentAttributes.FRAGMENT_COUNT.key();
+    public static final String SEGMENT_ORIGINAL_FILENAME = 
FragmentAttributes.SEGMENT_ORIGINAL_FILENAME.key();
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP Max Size")
+            .displayName("PCAP Max Size")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_ORIGINAL = new Relationship.Builder()
+            .name("original")
+            .description("The original FlowFile that was split into segments. 
If the FlowFile fails processing, nothing will be sent to "
+            + "this relationship")
+            .build();
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("If a FlowFile cannot be transformed from the 
configured input format to the configured output format, "
+            + "the unchanged FlowFile will be routed to this relationship.")
+            .build();
+    public static final Relationship REL_SPLIT = new Relationship.Builder()
+            .name("split")
+            .description("The individual PCAP 'segments' of the original PCAP 
FlowFile will be routed to this relationship.")
+            .build();
+
+    private static final int PCAP_HEADER_LENGTH = 24;
+    private static final int PACKET_HEADER_LENGTH = 16;
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+    private static final Set<Relationship> RELATIONSHIPS = 
Set.of(REL_ORIGINAL, REL_FAILURE, REL_SPLIT);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the PCAP Max Size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
+
+        final ByteArrayOutputStream contentBytes = new ByteArrayOutputStream();
+        session.exportTo(flowFile, contentBytes);
+        final byte[] contentByteArray = contentBytes.toByteArray();
+
+        if (contentByteArray.length == 0) {
+            session.putAttribute(flowFile, ERROR_REASON, "PCAP file empty.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        final PCAP parsedPcap;
+        final PCAP templatePcap;
+
+        // Parse the pcap file and create a template pcap object to borrow the 
header from.
+        try {
+            parsedPcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+            // Recreating rather than using deep copy as recreating is more 
efficient in this case.
+            templatePcap = new PCAP(new ByteBufferInterface(contentByteArray));
+
+        } catch (Exception e) {
+            session.putAttribute(flowFile, ERROR_REASON, "PCAP file not 
parseable.");
+            session.transfer(flowFile, REL_FAILURE);
+            return;
+        }
+
+        final List<Packet> unprocessedPackets = parsedPcap.packets();
+        List<FlowFile> splitFilesList = new ArrayList<>();

Review Comment:
   Please add `final` keyword
   ```suggestion
           final List<FlowFile> splitFilesList = new ArrayList<>();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,151 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+    private ByteBufferInterface io;
+    private final Logger logger = LoggerFactory.getLogger(Header.class);
+
+    public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root;
+        this.io = io;
+
+        try {
+            read();
+        } catch (ByteBufferInterface.ValidationNotEqualError e) {

Review Comment:
   Per earlier comment this can be replaced with 
   ```suggestion
           } catch (IllegalArgumentException e) {
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/test/java/org/apache/nifi/processors/network/pcap/TestSplitPCAP.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+
+public class TestSplitPCAP {
+
+    private Header hdr;
+    private Packet validPacket;
+    private Packet invalidPacket;
+
+    @BeforeEach
+    public void init() {
+        // Create a header for the test PCAP
+        this.hdr = new Header(
+            new byte[]{(byte) 0xa1, (byte) 0xb2, (byte) 0xc3, (byte) 0xd4},
+            2,
+            4,
+            0,
+            (long) 0,
+            (long) 40,
+            (long) 1 // ETHERNET
+        );
+
+        this.validPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 30,
+            (long) 30,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+        this.invalidPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 10,
+            (long) 10,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+    }
+
+    @Test
+    public void testValidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "100");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }
+
+        PCAP testPcap = new PCAP(this.hdr, packets);
+
+        runner.enqueue(testPcap.readBytesFull());
+
+        runner.run();
+
+        runner.assertTransferCount(SplitPCAP.REL_SPLIT, 3);
+        runner.assertTransferCount(SplitPCAP.REL_ORIGINAL, 1);
+        runner.assertQueueEmpty();
+    }
+
+    @Test
+    public void testInvalidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "50");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.invalidPacket);
+        }
+
+        PCAP testPcap = new PCAP(this.hdr, packets);
+
+        runner.enqueue(testPcap.readBytesFull());
+
+        runner.run();
+
+        runner.assertAllFlowFilesTransferred(SplitPCAP.REL_FAILURE, 1);
+        runner.assertQueueEmpty();
+    }
+
+    @Test
+    public void testPacketsTooBig() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "10");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }

Review Comment:
   ```suggestion
       @Test
       public void testPacketsTooBig() {
           TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
           runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "10");
   
            List<Packet> packets = Collections.nCopies(3, this.validPacket);
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/ByteBufferInterface.java:
##########
@@ -0,0 +1,87 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class ByteBufferInterface {
+
+    public ByteBufferInterface(byte[] byteArray) {
+        this.buffer = ByteBuffer.wrap(byteArray);
+    }
+
+    public static class ValidationNotEqualError extends Exception {
+        public ValidationNotEqualError(String message) {
+            super(message);
+        }
+    }

Review Comment:
   This can be removed and be replaced using commons-lang3 Validate (I will 
demonstrate where its used)
   ```suggestion
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/ByteBufferInterface.java:
##########
@@ -0,0 +1,87 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class ByteBufferInterface {
+
+    public ByteBufferInterface(byte[] byteArray) {
+        this.buffer = ByteBuffer.wrap(byteArray);
+    }
+
+    public static class ValidationNotEqualError extends Exception {
+        public ValidationNotEqualError(String message) {
+            super(message);
+        }
+    }
+
+    public ByteBuffer buffer;

Review Comment:
   Please place this towards the top of class before the constructor.
   ```suggestion
       public ByteBuffer buffer;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,151 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+    private ByteBufferInterface io;
+    private final Logger logger = LoggerFactory.getLogger(Header.class);
+
+    public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root;
+        this.io = io;
+
+        try {
+            read();
+        } catch (ByteBufferInterface.ValidationNotEqualError e) {
+            this.logger.error("PCAP file header could not be parsed due to ", 
e);
+        }
+    }
+
+    public Header(byte[] magicNumber, int versionMajor, int versionMinor, int 
thiszone, long sigfigs, long snaplen,
+            long network) {
+
+        this.magicNumber = magicNumber;
+        this.versionMajor = versionMajor;
+        this.versionMinor = versionMinor;
+        this.thiszone = thiszone;
+        this.sigfigs = sigfigs;
+        this.snaplen = snaplen;
+        this.network = network;
+    }
+
+    public ByteBufferInterface io() {
+        return io;
+    }
+
+    private void read()
+            throws ByteBufferInterface.ValidationNotEqualError {
+        this.magicNumber = this.io.readBytes(4);
+        if (this.magicNumber == new byte[] {(byte) 0xd4, (byte) 0xc3, (byte) 
0xb2, (byte) 0xa1 }) {
+            // have to swap the bits
+            this.versionMajor = this.io.readU2be();
+            if (!(versionMajor() == 2)) {
+
+                throw new ByteBufferInterface.ValidationNotEqualError("Packet 
major version is not 2.");
+            }
+            this.versionMinor = this.io.readU2be();
+            this.thiszone = this.io.readS4be();
+            this.sigfigs = this.io.readU4be();
+            this.snaplen = this.io.readU4be();
+            this.network = this.io.readU4be();
+        } else {
+            this.versionMajor = this.io.readU2le();
+            if (!(versionMajor() == 2)) {
+                throw new ByteBufferInterface.ValidationNotEqualError("Packet 
major version is not 2.");
+            }
+            this.versionMinor = this.io.readU2le();

Review Comment:
   ```suggestion
               Validate.isTrue(versionMajor() == 2, "Packet major version is 
not 2."); 
                
               this.versionMinor = this.io.readU2le();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/test/java/org/apache/nifi/processors/network/pcap/TestPCAP.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+
+import org.apache.nifi.processors.network.pcap.PCAP.Packet;
+import org.apache.nifi.processors.network.pcap.PCAP.Header;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestPCAP {
+    @Test
+    public void testReadBytesFull() {
+
+        // Create a header for the test PCAP
+        Header hdr = new Header(
+            new byte[]{(byte) 0xa1, (byte) 0xb2, (byte) 0xc3, (byte) 0xd4},
+            2,
+            4,
+            0,
+            (long) 0,
+            (long) 40,
+            (long) 1 // ETHERNET
+        );
+
+        // Create a sample packet
+        ArrayList<Packet> packets = new ArrayList<>();

Review Comment:
   The requested change was not applied



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/SplitPCAP.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.network.pcap;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.behavior.SideEffectFree;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.flowfile.attributes.FragmentAttributes;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.IntStream;
+
+@SideEffectFree
+@InputRequirement(Requirement.INPUT_REQUIRED)
+@Tags({"PCAP", "Splitter", "Network", "Packet", "Capture", "Wireshark", 
"TShark", "TcpDump", "WinDump", "sniffers"})
+@CapabilityDescription("Splits a pcap file into multiple pcap files based on a 
maximum size.")
+@WritesAttributes({
+    @WritesAttribute(
+        attribute = SplitPCAP.ERROR_REASON,
+        description = "The reason the flowfile was sent to the failure 
relationship."
+    ),
+    @WritesAttribute(
+        attribute = "fragment.identifier",
+        description = "All split PCAP FlowFiles produced from the same parent 
PCAP FlowFile will have the same randomly generated UUID added for this 
attribute"
+    ),
+    @WritesAttribute(
+        attribute = "fragment.index",
+        description = "A one-up number that indicates the ordering of the 
split PCAP FlowFiles that were created from a single parent PCAP FlowFile"
+    ),
+    @WritesAttribute(
+        attribute = "fragment.count",
+        description = "The number of split PCAP FlowFiles generated from the 
parent PCAP FlowFile"
+    ),
+    @WritesAttribute(
+        attribute = "segment.original.filename ",
+        description = "The filename of the parent PCAP FlowFile"
+    )
+})
+
+public class SplitPCAP extends AbstractProcessor {
+
+    protected static final String ERROR_REASON = "ERROR_REASON";
+    public static final String FRAGMENT_ID = 
FragmentAttributes.FRAGMENT_ID.key();
+    public static final String FRAGMENT_INDEX = 
FragmentAttributes.FRAGMENT_INDEX.key();
+    public static final String FRAGMENT_COUNT = 
FragmentAttributes.FRAGMENT_COUNT.key();
+    public static final String SEGMENT_ORIGINAL_FILENAME = 
FragmentAttributes.SEGMENT_ORIGINAL_FILENAME.key();
+
+    public static final PropertyDescriptor PCAP_MAX_SIZE = new 
PropertyDescriptor
+            .Builder().name("PCAP Max Size")
+            .displayName("PCAP Max Size")
+            .description("Maximum size of the output pcap file in bytes.")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_ORIGINAL = new Relationship.Builder()
+            .name("original")
+            .description("The original FlowFile that was split into segments. 
If the FlowFile fails processing, nothing will be sent to "
+            + "this relationship")
+            .build();
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("If a FlowFile cannot be transformed from the 
configured input format to the configured output format, "
+            + "the unchanged FlowFile will be routed to this relationship.")
+            .build();
+    public static final Relationship REL_SPLIT = new Relationship.Builder()
+            .name("split")
+            .description("The individual PCAP 'segments' of the original PCAP 
FlowFile will be routed to this relationship.")
+            .build();
+
+    private static final int PCAP_HEADER_LENGTH = 24;
+    private static final int PACKET_HEADER_LENGTH = 16;
+    private static final List<PropertyDescriptor> DESCRIPTORS = 
List.of(PCAP_MAX_SIZE);
+    private static final Set<Relationship> RELATIONSHIPS = 
Set.of(REL_ORIGINAL, REL_FAILURE, REL_SPLIT);
+
+    @Override
+    public Set<Relationship> getRelationships() {
+        return RELATIONSHIPS;
+    }
+
+    @Override
+    public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return DESCRIPTORS;
+    }
+
+    /**
+     * This method is called when a trigger event occurs in the processor.
+     * It processes the incoming flow file, splits it into smaller pcap files 
based on the PCAP Max Size,
+     * and transfers the split pcap files to the success relationship.
+     * If the flow file is empty or not parseable, it is transferred to the 
failure relationship.
+     *
+     * @param context  the process context
+     * @param session  the process session
+     */
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
session) {
+        FlowFile flowFile = session.get();
+        if (flowFile == null) {
+            return;
+        }
+
+        int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();

Review Comment:
   Please add `final` keyword
   ```suggestion
           final int pcapMaxSize = 
context.getProperty(PCAP_MAX_SIZE.getName()).asInteger();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/PCAP.java:
##########
@@ -0,0 +1,161 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PCAP (named after libpcap / winpcap) is a popular format for saving
+ * network traffic grabbed by network sniffers. It is typically
+ * produced by tools like [tcpdump](<a 
href="https://www.tcpdump.org/";>...</a>) or
+ * [Wireshark](<a href="https://www.wireshark.org/";>...</a>).
+ *
+ * @see <a href=
+ *      "https://wiki.wireshark.org/Development/LibpcapFileFormat";>Source</a>
+ */
+public class PCAP {
+    private ByteBufferInterface io;
+
+    public PCAP(ByteBufferInterface io) {
+        this(io, null, null);
+    }

Review Comment:
   ```suggestion
       private ByteBufferInterface io;
       private Header hdr;
       private List<Packet> packets;
       private PCAP root;
       private Object parent;
       
       public PCAP(ByteBufferInterface io) {
           this(io, null, null);
       }
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Packet.java:
##########
@@ -0,0 +1,98 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+public class Packet {
+    public ByteBufferInterface io;

Review Comment:
   Please change scope
   ```suggestion
       private ByteBufferInterface io;
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,151 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+    private ByteBufferInterface io;
+    private final Logger logger = LoggerFactory.getLogger(Header.class);
+
+    public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root;
+        this.io = io;
+
+        try {
+            read();
+        } catch (ByteBufferInterface.ValidationNotEqualError e) {
+            this.logger.error("PCAP file header could not be parsed due to ", 
e);
+        }
+    }
+
+    public Header(byte[] magicNumber, int versionMajor, int versionMinor, int 
thiszone, long sigfigs, long snaplen,
+            long network) {
+
+        this.magicNumber = magicNumber;
+        this.versionMajor = versionMajor;
+        this.versionMinor = versionMinor;
+        this.thiszone = thiszone;
+        this.sigfigs = sigfigs;
+        this.snaplen = snaplen;
+        this.network = network;
+    }
+
+    public ByteBufferInterface io() {
+        return io;
+    }
+
+    private void read()
+            throws ByteBufferInterface.ValidationNotEqualError {
+        this.magicNumber = this.io.readBytes(4);
+        if (this.magicNumber == new byte[] {(byte) 0xd4, (byte) 0xc3, (byte) 
0xb2, (byte) 0xa1 }) {
+            // have to swap the bits
+            this.versionMajor = this.io.readU2be();
+            if (!(versionMajor() == 2)) {
+
+                throw new ByteBufferInterface.ValidationNotEqualError("Packet 
major version is not 2.");
+            }
+            this.versionMinor = this.io.readU2be();

Review Comment:
   Replace with commons-lang3 `Validate`. The following import will be needed 
   `import org.apache.commons.lang3.Validate;`
   but no change to the pom.xml as I believe it is automatically included via 
the parent bom file.
   
   ```suggestion
               Validate.isTrue(versionMajor() == 2, "Packet major version is 
not 2.");
               
               this.versionMinor = this.io.readU2be();
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/test/java/org/apache/nifi/processors/network/pcap/TestSplitPCAP.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+
+public class TestSplitPCAP {
+
+    private Header hdr;
+    private Packet validPacket;
+    private Packet invalidPacket;
+
+    @BeforeEach
+    public void init() {
+        // Create a header for the test PCAP
+        this.hdr = new Header(
+            new byte[]{(byte) 0xa1, (byte) 0xb2, (byte) 0xc3, (byte) 0xd4},
+            2,
+            4,
+            0,
+            (long) 0,
+            (long) 40,
+            (long) 1 // ETHERNET
+        );
+
+        this.validPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 30,
+            (long) 30,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+        this.invalidPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 10,
+            (long) 10,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+    }
+
+    @Test
+    public void testValidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "100");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }
+
+        PCAP testPcap = new PCAP(this.hdr, packets);
+
+        runner.enqueue(testPcap.readBytesFull());
+
+        runner.run();
+
+        runner.assertTransferCount(SplitPCAP.REL_SPLIT, 3);
+        runner.assertTransferCount(SplitPCAP.REL_ORIGINAL, 1);
+        runner.assertQueueEmpty();
+    }
+
+    @Test
+    public void testInvalidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "50");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.invalidPacket);
+        }

Review Comment:
   ```suggestion
       @Test
       public void testInvalidPackets() {
           TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
           runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "50");
   
           List<Packet> packets = Collections.nCopies(3, this.invalidPacket);
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/test/java/org/apache/nifi/processors/network/pcap/TestSplitPCAP.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+
+public class TestSplitPCAP {
+
+    private Header hdr;
+    private Packet validPacket;
+    private Packet invalidPacket;
+
+    @BeforeEach
+    public void init() {
+        // Create a header for the test PCAP
+        this.hdr = new Header(
+            new byte[]{(byte) 0xa1, (byte) 0xb2, (byte) 0xc3, (byte) 0xd4},
+            2,
+            4,
+            0,
+            (long) 0,
+            (long) 40,
+            (long) 1 // ETHERNET
+        );
+
+        this.validPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 30,
+            (long) 30,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+        this.invalidPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 10,
+            (long) 10,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+    }
+
+    @Test
+    public void testValidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "100");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }
+
+        PCAP testPcap = new PCAP(this.hdr, packets);
+
+        runner.enqueue(testPcap.readBytesFull());
+
+        runner.run();
+
+        runner.assertTransferCount(SplitPCAP.REL_SPLIT, 3);
+        runner.assertTransferCount(SplitPCAP.REL_ORIGINAL, 1);
+        runner.assertQueueEmpty();
+    }
+
+    @Test
+    public void testInvalidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "50");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.invalidPacket);
+        }
+
+        PCAP testPcap = new PCAP(this.hdr, packets);
+
+        runner.enqueue(testPcap.readBytesFull());
+
+        runner.run();
+
+        runner.assertAllFlowFilesTransferred(SplitPCAP.REL_FAILURE, 1);
+        runner.assertQueueEmpty();
+    }
+
+    @Test
+    public void testPacketsTooBig() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "10");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }
+
+        PCAP testPcap = new PCAP(this.hdr, packets);
+
+        runner.enqueue(testPcap.readBytesFull());
+
+        runner.run();
+
+        runner.assertAllFlowFilesTransferred(SplitPCAP.REL_FAILURE, 1);
+        runner.assertQueueEmpty();
+    }
+
+    @Test
+    public void testOneInvalidPacket() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "10");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }

Review Comment:
   Note the need to instantiate an `ArrayList` as `nCopies` returns an 
immutable `List`.
   ```suggestion
       @Test
       public void testOneInvalidPacket() {
           TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
           runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "10");
   
           List<Packet> packets = new ArrayList<>(Collections.nCopies(3, 
this.validPacket));
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/test/java/org/apache/nifi/processors/network/pcap/TestSplitPCAP.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.nifi.processors.network.pcap;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+
+public class TestSplitPCAP {
+
+    private Header hdr;
+    private Packet validPacket;
+    private Packet invalidPacket;
+
+    @BeforeEach
+    public void init() {
+        // Create a header for the test PCAP
+        this.hdr = new Header(
+            new byte[]{(byte) 0xa1, (byte) 0xb2, (byte) 0xc3, (byte) 0xd4},
+            2,
+            4,
+            0,
+            (long) 0,
+            (long) 40,
+            (long) 1 // ETHERNET
+        );
+
+        this.validPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 30,
+            (long) 30,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+        this.invalidPacket = new Packet(
+            (long) 1713184965,
+            (long) 1000,
+            (long) 10,
+            (long) 10,
+            new byte[]{
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
+                10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+                20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+            }
+        );
+
+    }
+
+    @Test
+    public void testValidPackets() throws IOException {
+        TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
+        runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "100");
+
+        List<Packet> packets = new ArrayList<>();
+        for (var loop = 0; loop < 3; loop++) {
+            packets.add(this.validPacket);
+        }

Review Comment:
   Intellij says the `throws` is not necessary as an `IOException` is not being 
thrown.
   It turns out Java already has a method to repeat an object in a collection 
as seen below.
   Please include `import java.util.Collections;`.
   
   ```suggestion
       public void testValidPackets()  {
           TestRunner runner = TestRunners.newTestRunner(SplitPCAP.class);
           runner.setProperty(SplitPCAP.PCAP_MAX_SIZE, "100");
   
            List<Packet> packets = Collections.nCopies(3, this.validPacket);
   ```



##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,151 @@
+// MIT License
+
+// Copyright (c) 2015-2023 Kaitai Project
+
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to 
deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+
+// The above copyright notice and this permission notice shall be included in 
all
+// copies or substantial portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE
+// SOFTWARE.
+
+package org.apache.nifi.processors.network.pcap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+    private ByteBufferInterface io;
+    private final Logger logger = LoggerFactory.getLogger(Header.class);
+
+    public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+        this.parent = parent;
+        this.root = root;
+        this.io = io;
+
+        try {
+            read();
+        } catch (ByteBufferInterface.ValidationNotEqualError e) {
+            this.logger.error("PCAP file header could not be parsed due to ", 
e);
+        }
+    }
+
+    public Header(byte[] magicNumber, int versionMajor, int versionMinor, int 
thiszone, long sigfigs, long snaplen,
+            long network) {
+
+        this.magicNumber = magicNumber;
+        this.versionMajor = versionMajor;
+        this.versionMinor = versionMinor;
+        this.thiszone = thiszone;
+        this.sigfigs = sigfigs;
+        this.snaplen = snaplen;
+        this.network = network;
+    }
+
+    public ByteBufferInterface io() {
+        return io;
+    }
+
+    private void read()
+            throws ByteBufferInterface.ValidationNotEqualError {

Review Comment:
   Per earlier comment
   ```suggestion
       private void read() {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to