Dispose() protected method

Closes the input stream. When is true the underlying stream is also closed.
protected Dispose ( bool disposing ) : void
disposing bool
return void
コード例 #1
0
        private string ParseQpyd(string qqydFile)
        {
            var fs = new FileStream(qqydFile, FileMode.Open, FileAccess.Read);
            fs.Position = 0x38;
            var startAddressByte = new byte[4];
            fs.Read(startAddressByte, 0, 4);
            int startAddress = BitConverter.ToInt32(startAddressByte, 0);
            fs.Position = 0x44;
            int wordCount = BinFileHelper.ReadInt32(fs);
            CountWord = wordCount;
            CurrentStatus = 0;

            fs.Position = startAddress;
            var zipStream = new InflaterInputStream(fs);


            int bufferSize = 2048; //缓冲区大小
            int readCount = 0; //读入缓冲区的实际字节
            var buffer = new byte[bufferSize];
            var byteList = new List<byte>();
            readCount = zipStream.Read(buffer, 0, bufferSize);
            while (readCount > 0)
            {
                for (int i = 0; i < readCount; i++)
                {
                    byteList.Add(buffer[i]);
                }
                readCount = zipStream.Read(buffer, 0, bufferSize);
            }
            zipStream.Close();
            zipStream.Dispose();
            fs.Close();

            byte[] byteArray = byteList.ToArray();

            int unzippedDictStartAddr = -1;
            int idx = 0;
            var sb = new StringBuilder();
            while (unzippedDictStartAddr == -1 || idx < unzippedDictStartAddr)
            {
                // read word

                int pinyinStartAddr = BitConverter.ToInt32(byteArray, idx + 0x6);
                int pinyinLength = BitConverter.ToInt32(byteArray, idx + 0x0) & 0xff;
                int wordStartAddr = pinyinStartAddr + pinyinLength;
                int wordLength = BitConverter.ToInt32(byteArray, idx + 0x1) & 0xff;
                if (unzippedDictStartAddr == -1)
                {
                    unzippedDictStartAddr = pinyinStartAddr;
                    Debug.WriteLine("词库地址(解压后):0x" + unzippedDictStartAddr.ToString("0x") + "\n");
                }

                string pinyin = Encoding.UTF8.GetString(byteArray, pinyinStartAddr, pinyinLength);
                string word = Encoding.Unicode.GetString(byteArray, wordStartAddr, wordLength);
                sb.Append(word + "\t" + pinyin + "\n");
                Debug.WriteLine(word + "\t" + pinyin);
                CurrentStatus++;
                // step up
                idx += 0xa;
            }
            return sb.ToString();
        }