private MessageHeader_Format parseHeaderAndVerifyStoreKey(InputStream is, int indexInReadSet)
      throws MessageFormatException, IOException {
    // read and verify header version
    byte[] headerVersionBytes = new byte[Version_Field_Size_In_Bytes];
    is.read(headerVersionBytes, 0, Version_Field_Size_In_Bytes);
    short version = ByteBuffer.wrap(headerVersionBytes).getShort();
    if (!isValidHeaderVersion(version)) {
      throw new MessageFormatException(
          "Version not known while reading message - version " + version + ", StoreKey " + readSet.getKeyAt(
              indexInReadSet), MessageFormatErrorCodes.UnknownFormatVersion);
    }

    // read and verify header
    byte[] headerBytes = new byte[getHeaderSizeForVersion(version)];
    is.read(headerBytes, Version_Field_Size_In_Bytes, headerBytes.length - Version_Field_Size_In_Bytes);

    ByteBuffer header = ByteBuffer.wrap(headerBytes);
    header.putShort(version);
    header.rewind();
    MessageHeader_Format headerFormat = getMessageHeader(version, header);
    headerFormat.verifyHeader();

    // read and verify storeKey
    StoreKey storeKey = storeKeyFactory.getStoreKey(new DataInputStream(is));
    if (storeKey.compareTo(readSet.getKeyAt(indexInReadSet)) != 0) {
      throw new MessageFormatException(
          "Id mismatch between metadata and store - metadataId " + readSet.getKeyAt(indexInReadSet) + " storeId "
              + storeKey, MessageFormatErrorCodes.StoreKeyIdMisMatch);
    }
    return headerFormat;
  }
Parse and verify header + storeKey from given inputStream.
ambry-messageformat/src/main/java/com/github/ambry/messageformat/MessageFormatSend.java