dan-s1 commented on code in PR #8691:
URL: https://github.com/apache/nifi/pull/8691#discussion_r1610194288
##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,147 @@
+// MIT License
+
+// Copyright (c) 2015-2024 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.apache.commons.lang3.Validate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+ private static final Logger logger = LoggerFactory.getLogger(Header.class);
+ private ByteBufferInterface io;
+
+ public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+ this.parent = parent;
+ this.root = root;
+ this.io = io;
+
+ try {
+ read();
+ } catch (IllegalArgumentException e) {
+ this.logger.error("PCAP file header could not be parsed due to ",
e);
Review Comment:
No need for `this` as `logger` is static
```suggestion
logger.error("PCAP file header could not be parsed due to ", e);
```
##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,147 @@
+// MIT License
+
+// Copyright (c) 2015-2024 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.apache.commons.lang3.Validate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+ private static final Logger logger = LoggerFactory.getLogger(Header.class);
+ private ByteBufferInterface io;
+
+ public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+ this.parent = parent;
+ this.root = root;
+ this.io = io;
+
+ try {
+ read();
+ } catch (IllegalArgumentException 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() {
+ 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();
+ Validate.isTrue(versionMajor() == 2, "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();
+ Validate.isTrue(versionMajor() == 2, "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();
+ }
+ }
+
+ private byte[] magicNumber;
+ private int versionMajor;
+ private int versionMinor;
+ private int thiszone;
+ private long sigfigs;
+ private long snaplen;
+ private long network;
+ private PCAP root;
+ private PCAP parent;
Review Comment:
Please place these after `private ByteBufferInterface io;` defined on line
32
```suggestion
```
##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,147 @@
+// MIT License
+
+// Copyright (c) 2015-2024 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.apache.commons.lang3.Validate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+ private static final Logger logger = LoggerFactory.getLogger(Header.class);
+ private ByteBufferInterface io;
Review Comment:
```suggestion
private ByteBufferInterface io;
private byte[] magicNumber;
private int versionMajor;
private int versionMinor;
private int thiszone;
private long sigfigs;
private long snaplen;
private long network;
private PCAP root;
private PCAP parent;
```
##########
nifi-extension-bundles/nifi-network-bundle/nifi-network-processors/src/main/java/org/apache/nifi/processors/network/pcap/Header.java:
##########
@@ -0,0 +1,147 @@
+// MIT License
+
+// Copyright (c) 2015-2024 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.apache.commons.lang3.Validate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Header {
+ private static final Logger logger = LoggerFactory.getLogger(Header.class);
+ private ByteBufferInterface io;
+
+ public Header(ByteBufferInterface io, PCAP parent, PCAP root) {
+
+ this.parent = parent;
+ this.root = root;
+ this.io = io;
+
+ try {
+ read();
+ } catch (IllegalArgumentException 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() {
+ this.magicNumber = this.io.readBytes(4);
+ if (this.magicNumber == new byte[] {(byte) 0xd4, (byte) 0xc3, (byte)
0xb2, (byte) 0xa1 }) {
Review Comment:
Suggestion per Intellij as comparison with `==`could yield an NPE. Please
also include
`import java.util.Arrays;`
```suggestion
if (Arrays.equals(this.magicNumber, new byte[]{(byte) 0xd4, (byte)
0xc3, (byte) 0xb2, (byte) 0xa1})) {
```
--
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]