ReadInt() public method

Reads four bytes and returns an int.
public ReadInt ( ) : int
return int
Esempio n. 1
0
        /// <summary>
        /// Like {@link
        ///  #checkHeader(DataInput,String,int,int)} except this
        ///  version assumes the first int has already been read
        ///  and validated from the input.
        /// </summary>
        public static int CheckHeaderNoMagic(DataInput @in, string codec, int minVersion, int maxVersion)
        {
            string actualCodec = @in.ReadString();
            if (!actualCodec.Equals(codec))
            {
                throw new System.IO.IOException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec + " (resource: " + @in + ")");
            }

            int actualVersion = @in.ReadInt();
            if (actualVersion < minVersion)
            {
                throw new System.IO.IOException("Version: " + actualVersion + " is not supported. Minimum Version number is " + minVersion + ".");
            }
            if (actualVersion > maxVersion)
            {
                throw new System.IO.IOException("Version: " + actualVersion + " is not supported. Maximum Version number is " + maxVersion + ".");
            }

            return actualVersion;
        }
Esempio n. 2
0
 /// <summary>
 /// Reads and validates a header previously written with
 /// <seealso cref="#writeHeader(DataOutput, String, int)"/>.
 /// <p>
 /// When reading a file, supply the expected <code>codec</code> and
 /// an expected version range (<code>minVersion to maxVersion</code>).
 /// </summary>
 /// <param name="in"> Input stream, positioned at the point where the
 ///        header was previously written. Typically this is located
 ///        at the beginning of the file. </param>
 /// <param name="codec"> The expected codec name. </param>
 /// <param name="minVersion"> The minimum supported expected version number. </param>
 /// <param name="maxVersion"> The maximum supported expected version number. </param>
 /// <returns> The actual version found, when a valid header is found
 ///         that matches <code>codec</code>, with an actual version
 ///         where <code>minVersion <= actual <= maxVersion</code>.
 ///         Otherwise an exception is thrown. </returns>
 /// <exception cref="CorruptIndexException"> If the first four bytes are not
 ///         <seealso cref="#CODEC_MAGIC"/>, or if the actual codec found is
 ///         not <code>codec</code>. </exception>
 /// <exception cref="IndexFormatTooOldException"> If the actual version is less
 ///         than <code>minVersion</code>. </exception>
 /// <exception cref="IndexFormatTooNewException"> If the actual version is greater
 ///         than <code>maxVersion</code>. </exception>
 /// <exception cref="IOException"> If there is an I/O error reading from the underlying medium. </exception>
 /// <seealso cref= #writeHeader(DataOutput, String, int) </seealso>
 public static int CheckHeader(DataInput @in, string codec, int minVersion, int maxVersion)
 {
     // Safety to guard against reading a bogus string:
     int actualHeader = @in.ReadInt();
     if (actualHeader != CODEC_MAGIC)
     {
         throw new System.IO.IOException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC + " (resource: " + @in + ")");
     }
     return CheckHeaderNoMagic(@in, codec, minVersion, maxVersion);
 }