public static MessageHeader_Format getHeader(DataInputStream stream) throws IOException, MessageFormatException {
    short version = stream.readShort();
    if (!isValidHeaderVersion(version)) {
      throw new MessageFormatException("Version not known while reading message - " + version,
          MessageFormatErrorCodes.UnknownFormatVersion);
    }
    byte[] bytes = new byte[getHeaderSizeForVersion(version)];
    Utils.readBytesFromStream(stream, bytes, Short.BYTES, bytes.length - Short.BYTES);
    ByteBuffer buf = ByteBuffer.wrap(bytes);
    buf.putShort(version);
    buf.rewind();
    MessageHeader_Format header = getMessageHeader(version, buf);
    header.verifyHeader();
    return header;
  }
@param stream stream that contains data
@return the header as extracted from the {@code stream}
@throws IOException
@throws MessageFormatException
ambry-messageformat/src/test/java/com/github/ambry/messageformat/MessageFormatRecordTest.java