private ByteBuffer checkFileDataIntegrity(File fileToRead) throws StoreException {
    if (!fileToRead.exists()) {
      throw new StoreException("Index segment file " + fileToRead.getAbsolutePath() + " doesn't exist",
          StoreErrorCodes.FileNotFound);
    }
    ByteBuffer byteBuffer = ByteBuffer.allocate((int) fileToRead.length());
    try (FileInputStream fileInputStream = new FileInputStream(fileToRead)) {
      Utils.readFileToByteBuffer(fileInputStream.getChannel(), 0, byteBuffer);
      if (!checkDataIntegrityInByteBufferWithCRC(byteBuffer)) {
        throw new StoreException("IndexSegment : " + indexFile.getAbsolutePath() + " crc check does not match",
            StoreErrorCodes.IndexFileFormatError);
      }
    } catch (IOException e) {
      StoreErrorCodes errorCode = StoreException.resolveErrorCode(e);
      throw new StoreException("IndexSegment : " + indexFile.getAbsolutePath() + " encountered " + errorCode.toString()
          + " while reading from file ", e, errorCode);
    }
    return byteBuffer;
  }
Read all the data from the given file and check if the crc value matches.
@param fileToRead The file to read data from.
@return A {@link ByteBuffer} that contains all the data in the file, including crc value.
@throws StoreException
ambry-store/src/main/java/com/github/ambry/store/IndexSegment.java