void setEndOffset(long endOffset) throws StoreException {
    try {
      long fileSize = sizeInBytes();
      if (endOffset < startOffset || endOffset > fileSize) {
        throw new StoreException(new IllegalArgumentException(
            file.getAbsolutePath() + ": EndOffset [" + endOffset + "] outside the file size [" + fileSize + "]"),
            StoreErrorCodes.LogEndOffsetError);
      }
      fileChannel.position(endOffset);
      this.endOffset.set(endOffset);
    } catch (IOException e) {
      StoreErrorCodes errorCode = StoreException.resolveErrorCode(e);
      throw new StoreException(errorCode.toString() + " while setting end offset of segment", e, errorCode);
    }
  }
Sets the end offset of this segment. This can be lesser than the actual size of the file and represents the offset
until which data that is readable is stored (exclusive) and the offset (inclusive) from which the next append will
begin.
@param endOffset the end offset of this log.
@throws IllegalArgumentException if {@code endOffset} < header size or {@code endOffset} > the size of the file.
@throws StoreException if there is any store related exception.
ambry-store/src/main/java/com/github/ambry/store/LogSegment.java