public static void positionToNextBuffer(FileChannel channel, ByteBuffer headerBuffer)
            throws IOException {
        headerBuffer.clear();
        if (!tryReadByteBuffer(channel, headerBuffer)) {
            throwCorruptDataException();
        }
        headerBuffer.flip();

        try {
            headerBuffer.getShort();
            headerBuffer.getShort();
            long bufferSize = headerBuffer.getInt();
            channel.position(channel.position() + bufferSize);
        } catch (BufferUnderflowException | IllegalArgumentException e) {
            // buffer underflow if header buffer is undersized
            // IllegalArgumentException if size is outside memory segment size
            throwCorruptDataException();
        }
    }
@Test
    void testPositionToNextBuffer(@TempDir Path tempPath) throws Exception {
        final FileChannel fc = tmpFileChannel(tempPath);
        ByteBuffer[] byteBuffersWithHeader = createByteBuffersWithHeader(2);
        long totalBytes =
                Arrays.stream(byteBuffersWithHeader).mapToLong(ByteBuffer::remaining).sum();
        BufferReaderWriterUtil.writeBuffers(fc, totalBytes, byteBuffersWithHeader);
        // reset the channel's position to read.
        fc.position(0);
        BufferReaderWriterUtil.positionToNextBuffer(fc, byteBuffersWithHeader[0]);
        long expectedPosition = totalBytes / 2;
        assertThat(fc.position()).isEqualTo(expectedPosition);
    }