Exemplo n.º 1
0
        private void ReadUntilStreamIsSynchronized()
        {
            while (true)
            {
                if (Stream.PeekByte(0) != PACKET_START_MAGIC)
                {
                    this.ReadUntil(PACKET_START_MAGIC);
                }

                int header          = Stream.PeekByte(1);
                int payloadLength   = header & PAYLOAD_LENGTH_BIT_MASK;
                int nextPacketStart = Stream.PeekByte(HEADER_LENGTH + payloadLength);

                if (nextPacketStart == PACKET_START_MAGIC || nextPacketStart == -1)
                {
                    return;
                }
                else
                {
                    this.ReadAfter(PACKET_START_MAGIC);
                }
            }
        }
Exemplo n.º 2
0
        public ClilocList(string language)
        {
            m_Language = language;
            m_Table    = new Hashtable();

            string path = ClilocPath + language;

            if (path == null)
            {
                m_Entries = new ClilocEntry[0];
                return;
            }

            ArrayList list = new ArrayList();

            using (BinaryReader bin = new BinaryReader(new PeekableStream(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))))
            {
                PeekableStream PeekableStream = bin.BaseStream as PeekableStream;
                bin.ReadInt32();
                bin.ReadInt16();

                while (PeekableStream.PeekByte() != -1)
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte();
                    int length = bin.ReadInt16();

                    if (length > m_Buffer.Length)
                    {
                        m_Buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(m_Buffer, 0, length);
                    string text = Encoding.UTF8.GetString(m_Buffer, 0, length);

                    list.Add(new ClilocEntry(number, text));
                    m_Table[number] = text;
                }
            }

            m_Entries = (ClilocEntry[])list.ToArray(typeof(ClilocEntry));
        }