FlickrNet.Utils.ReadString C# (CSharp) Method

ReadString() static private method

static private ReadString ( Stream s ) : string
s Stream
return string
        internal static string ReadString(Stream s)
        {
            int len = ReadInt32(s);
            char[] chars = new char[len];
            for (int i = 0; i < len; i++)
            {
                int hi, lo;
                lo = s.ReadByte();
                hi = s.ReadByte();
                if (lo == -1 || hi == -1)
                    throw new IOException("Unexpected EOF encountered");
                chars[i] = (char) (lo | (hi << 8));
            }
            return new string(chars);
        }

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);
        }
All Usage Examples Of FlickrNet.Utils::ReadString