FlickrNet.Utils.ReadInt32 C# (CSharp) Method

ReadInt32() static private method

static private ReadInt32 ( Stream s ) : int
s Stream
return int
        internal static int ReadInt32(Stream s)
        {
            int i = 0, b;
            for (int j = 0; j < 4; j++)
            {
                b = s.ReadByte();
                if (b == -1)
                    throw new IOException("Unexpected EOF encountered");
                i |= (b << (j * 8));
            }
            return i;
        }

Usage Example

        private Hashtable Load(Stream s)
        {
            Hashtable table     = new Hashtable();
            int       itemCount = Utils.ReadInt32(s);

            for (int i = 0; i < itemCount; i++)
            {
                try
                {
                    string     key = Utils.ReadString(s);
                    ICacheItem val = persister.Read(s);
                    if (val == null)                      // corrupt cache file
                    {
                        return(table);
                    }

                    table[key] = val;
                }
                catch (IOException)
                {
                    return(table);
                }
            }
            return(table);
        }