private void validateReadRange(long position, int length) throws IOException {
    long sizeInBytes = sizeInBytes();
    if (position < startOffset || position >= sizeInBytes) {
      throw new IndexOutOfBoundsException(
          "Provided position [" + position + "] is out of bounds for the segment [" + file.getAbsolutePath()
              + "] with size [" + sizeInBytes + "]");
    }
    if (position + length > sizeInBytes) {
      metrics.overflowReadError.inc();
      throw new IndexOutOfBoundsException(
          "Cannot read from segment [" + file.getAbsolutePath() + "] from position [" + position + "] for size ["
              + length + "] because it exceeds the size [" + sizeInBytes + "]");
    }
  }
Verify read is in a valid range of {@link LogSegment#fileChannel}.
@param position The position to start the read.
@param length The length of data in bytes to read.
ambry-store/src/main/java/com/github/ambry/store/LogSegment.java