public byte[] read(final long logIndex, final int pos) throws IOException {
        assert (pos >= HEADER_SIZE);
        swapInIfNeed();
        this.readLock.lock();
        try {
            if (logIndex < this.header.firstLogIndex || logIndex > this.lastLogIndex) {
                LOG.warn(
                    "Try to read data from segment file {} out of range, logIndex={}, readPos={}, firstLogIndex={}, lastLogIndex={}.",
                    this.path, logIndex, pos, this.header.firstLogIndex, this.lastLogIndex);
                return null;
            }
            if (pos >= this.committedPos) {
                LOG.warn(
                    "Try to read data from segment file {} out of comitted position, logIndex={}, readPos={}, wrotePos={}, this.committedPos={}.",
                    this.path, logIndex, pos, this.wrotePos, this.committedPos);
                return null;
            }
            final ByteBuffer readBuffer = this.buffer.asReadOnlyBuffer();
            readBuffer.position(pos);
            if (readBuffer.remaining() < RECORD_MAGIC_BYTES_SIZE) {
                throw new IOException("Missing magic buffer.");
            }
            readBuffer.position(pos + RECORD_MAGIC_BYTES_SIZE);
            final int dataLen = readBuffer.getInt();
            //TODO(boyan) reuse data array?
            final byte[] data = new byte[dataLen];
            readBuffer.get(data);
            return data;
        } finally {
            this.readLock.unlock();
        }
    }
Read data from the position.

@param logIndex the log index
@param pos      the position to read
@return read data
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/log/SegmentFile.java