private static void skipBytes(InputStream in, int bytesToSkip) throws IOException {
        if (bytesToSkip <= 0) return;

        // Starting JDK 12, this implementation could be replaced by InputStream#skipNBytes
        while (bytesToSkip > 0) {
            int ns = (int) in.skip(bytesToSkip);
            if (ns > 0 && ns <= bytesToSkip) {
                // adjust number to skip
                bytesToSkip -= ns;
            } else if (ns == 0) { // no bytes skipped
                // read one byte to check for EOS
                if (in.read() == -1) {
                    throw new InvalidRecordException("Reached end of input stream before skipping all bytes. " +
                        "Remaining bytes:" + bytesToSkip);
                }
                // one byte read so decrement number to skip
                bytesToSkip--;
            } else { // skipped negative or too many bytes
                throw new IOException("Unable to skip exactly");
            }
        }
    }
Skips over and discards exactly {@code bytesToSkip} bytes from the input stream.

We require a loop over {@link InputStream#skip(long)} because it is possible for InputStream to skip smaller
number of bytes than expected (see javadoc for InputStream#skip).

No-op for case where bytesToSkip <= 0. This could occur for cases where field is expected to be null.
@throws InvalidRecordException if end of stream is encountered before we could skip required bytes.
@throws IOException is an I/O error occurs while trying to skip from InputStream.

@see java.io.InputStream#skip(long)
clients/src/main/java/org/apache/kafka/common/record/DefaultRecord.java