/// <summary>
/// Writes a codec header, which records both a string to
/// identify the file and a version number. this header can
/// be parsed and validated with
/// <seealso cref="#checkHeader(DataInput, String, int, int) checkHeader()"/>.
/// <p>
/// CodecHeader --> Magic,CodecName,Version
/// <ul>
/// <li>Magic --> <seealso cref="DataOutput#writeInt Uint32"/>. this
/// identifies the start of the header. It is always {@value #CODEC_MAGIC}.
/// <li>CodecName --> <seealso cref="DataOutput#writeString String"/>. this
/// is a string to identify this file.
/// <li>Version --> <seealso cref="DataOutput#writeInt Uint32"/>. Records
/// the version of the file.
/// </ul>
/// <p>
/// Note that the length of a codec header depends only upon the
/// name of the codec, so this length can be computed at any time
/// with <seealso cref="#headerLength(String)"/>.
/// </summary>
/// <param name="out"> Output stream </param>
/// <param name="codec"> String to identify this file. It should be simple ASCII,
/// less than 128 characters in length. </param>
/// <param name="version"> Version number </param>
/// <exception cref="IOException"> If there is an I/O error writing to the underlying medium. </exception>
public static void WriteHeader(DataOutput @out, string codec, int version)
{
BytesRef bytes = new BytesRef(codec);
if (bytes.Length != codec.Length || bytes.Length >= 128)
{
throw new System.ArgumentException("codec must be simple ASCII, less than 128 characters in length [got " + codec + "]");
}
@out.WriteInt(CODEC_MAGIC);
@out.WriteString(codec);
@out.WriteInt(version);
}