Source:
<code>public PcapNgFile(Path filePath) throws BadPcapFileException, IOException { super(filePath); ByteOrder byteOrder; TreeMap<Long, Long> fileIndex = getFileIndex(); setCurrentRank(0); SeekableByteChannel fileChannel = getFileChannel(); int magicNumber; ByteBuffer header = ByteBuffer.allocate(PcapFileValues.PCAPNG_BLOCK_HEADER_SIZE); header.order(ByteOrder.LITTLE_ENDIAN); fileChannel.read(header); header.flip(); int blockType = header.getInt(); if (blockType != PcapFileValues.PCAPNG_SHB) { this.close(); throw new BadPcapFileException(String.format("0x%08x", blockType) + " Missing Section Header Block."); } ENDIAN as byte order as default int headerLen = header.getInt(); ENDIAN as if (headerLen > 0xFFFF) { header.flip(); header.order(ByteOrder.BIG_ENDIAN); header.getInt(); <START> headerLen = header.getInt(); <END> } header = ByteBuffer.allocate(headerLen - PcapFileValues.PCAPNG_BLOCK_HEADER_SIZE); header.clear(); fileChannel.read(header); header.flip(); magicNumber = header.getInt(); switch (magicNumber) { case PcapFileValues.MAGIC_LITTLE_ENDIAN_NG: byteOrder = ByteOrder.LITTLE_ENDIAN; break; case PcapFileValues.MAGIC_BIG_ENDIAN_NG: byteOrder = ByteOrder.BIG_ENDIAN; break; default: this.close(); throw new BadPcapFileException(String.format("%08x", magicNumber) + " is not a valid Byte-Order Magic value."); } header.order(byteOrder); int majorVersion = ConversionHelper.unsignedShortToInt(header.getShort()); int minorVersion = ConversionHelper.unsignedShortToInt(header.getShort()); fileIndex.put(getCurrentRank(), fileChannel.position()); setCurrentRank(getCurrentRank()); init(byteOrder, majorVersion, minorVersion, PcapTimestampScale.MICROSECOND); }</code><technical_language>need read again. Integer.reverseBytes()</technical_language>

Target:
public PcapNgFile(Path filePath) throws BadPcapFileException, IOException { super(filePath); ByteOrder byteOrder; TreeMap<Long, Long> fileIndex = getFileIndex(); setCurrentRank(0); SeekableByteChannel fileChannel = getFileChannel(); int magicNumber; ByteBuffer header = ByteBuffer.allocate(PcapFileValues.PCAPNG_BLOCK_HEADER_SIZE); header.order(ByteOrder.LITTLE_ENDIAN); fileChannel.read(header); header.flip(); int blockType = header.getInt(); if (blockType != PcapFileValues.PCAPNG_SHB) { this.close(); throw new BadPcapFileException(String.format("0x%08x", blockType) + " Missing Section Header Block."); } ENDIAN as byte order as default int headerLen = header.getInt(); ENDIAN as if (headerLen > 0xFFFF) { header.order(ByteOrder.BIG_ENDIAN); headerLen = Integer.reverseBytes(headerLen); } header = ByteBuffer.allocate(headerLen - PcapFileValues.PCAPNG_BLOCK_HEADER_SIZE); fileChannel.read(header); header.flip(); magicNumber = header.getInt(); switch (magicNumber) { case PcapFileValues.MAGIC_LITTLE_ENDIAN_NG: byteOrder = ByteOrder.LITTLE_ENDIAN; break; case PcapFileValues.MAGIC_BIG_ENDIAN_NG: byteOrder = ByteOrder.BIG_ENDIAN; break; default: this.close(); throw new BadPcapFileException(String.format("%08x", magicNumber) + " is not a valid Byte-Order Magic value."); } header.order(byteOrder); int majorVersion = ConversionHelper.unsignedShortToInt(header.getShort()); int minorVersion = ConversionHelper.unsignedShortToInt(header.getShort()); fileIndex.put(getCurrentRank(), fileChannel.position()); setCurrentRank(getCurrentRank()); init(byteOrder, majorVersion, minorVersion); }