當前位置: 首頁>>代碼示例>>C#>>正文


C# Stream.Read方法代碼示例

本文整理匯總了C#中System.Stream.Read方法的典型用法代碼示例。如果您正苦於以下問題:C# Stream.Read方法的具體用法?C# Stream.Read怎麽用?C# Stream.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Stream的用法示例。


在下文中一共展示了Stream.Read方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReadBytes

 public static void ReadBytes(Stream s, byte[] b, int offset, int length)
 {
     if ((offset == 0) && (length == 0))
         length = b.Length;
     while (length > 0)
     {
         int count = s.Read(b, offset, length);
         if (count <= 0)
             throw new Exception("IOException: EOF");
         offset += count;
         length -= count;
     }
 }
開發者ID:divyang4481,項目名稱:bclcontrib-scriptsharp,代碼行數:13,代碼來源:SE.cs

示例2: Store

        // Copies all source file into storage file
        private void Store(ref ZipFileEntry _zfe, Stream _source)
        {
            byte[] buffer = new byte[16384];
             int bytesRead;
             uint totalRead = 0;
             Stream outStream;

             long posStart = this.ZipFileStream.Position;
             long sourceStart = _source.Position;

             if (_zfe.Method == Compression.Store)
                 outStream = this.ZipFileStream;
             else
                 outStream = new DeflateStream(this.ZipFileStream, CompressionMode.Compress, true);

             _zfe.Crc32 = 0 ^ 0xffffffff;

             do
             {
                 bytesRead = _source.Read(buffer, 0, buffer.Length);
                 totalRead += (uint)bytesRead;
                 if (bytesRead > 0)
                 {
                     outStream.Write(buffer, 0, bytesRead);

                     for (uint i = 0; i < bytesRead; i++)
                     {
                         _zfe.Crc32 = ZipStorer.CrcTable[(_zfe.Crc32 ^ buffer[i]) & 0xFF] ^ (_zfe.Crc32 >> 8);
                     }
                 }
             } while (bytesRead == buffer.Length);
             outStream.Flush();

             if (_zfe.Method == Compression.Deflate)
                 outStream.Dispose();

             _zfe.Crc32 ^= 0xffffffff;
             _zfe.FileSize = totalRead;
             _zfe.CompressedSize = (uint)(this.ZipFileStream.Position - posStart);

             // Verify for real compression
             if (_zfe.Method == Compression.Deflate && !this.ForceDeflating && _source.CanSeek && _zfe.CompressedSize > _zfe.FileSize)
             {
                 // Start operation again with Store algorithm
                 _zfe.Method = Compression.Store;
                 this.ZipFileStream.Position = posStart;
                 this.ZipFileStream.SetLength(posStart);
                 _source.Position = sourceStart;
                 this.Store(ref _zfe, _source);
             }
        }
開發者ID:aswartzbaugh,項目名稱:biketour,代碼行數:52,代碼來源:ZipStorer.cs

示例3: CopyToMemoryStream

        private static Stream CopyToMemoryStream(Stream s) {
            var size = 100000; // large heap is more efficient
            var copyBuff = new byte[size];
            int len;
            var r = new MemoryStream();
            while((len = s.Read(copyBuff, 0, size)) > 0)
                r.Write(copyBuff, 0, len);

            r.Seek(0, SeekOrigin.Begin);
            s.Close();
            return r;
        }
開發者ID:roomaroo,項目名稱:coapp.powershell,代碼行數:12,代碼來源:SgmlParseException.cs

示例4: HtmlStream

        public HtmlStream(Stream stm, Encoding defaultEncoding) {
            if(defaultEncoding == null) {
                defaultEncoding = Encoding.UTF8; // default is UTF8
            }
            if(!stm.CanSeek) {
                // Need to be able to seek to sniff correctly.
                stm = CopyToMemoryStream(stm);
            }
            this.stm = stm;
            rawBuffer = new Byte[BUFSIZE];
            rawUsed = stm.Read(rawBuffer, 0, 4); // maximum byte order mark
            this.m_buffer = new char[BUFSIZE];

            // Check byte order marks
            this.m_decoder = AutoDetectEncoding(rawBuffer, ref rawPos, rawUsed);
            var bom = rawPos;
            if(this.m_decoder == null) {
                this.m_decoder = defaultEncoding.GetDecoder();
                rawUsed += stm.Read(rawBuffer, 4, BUFSIZE - 4);
                DecodeBlock();
                // Now sniff to see if there is an XML declaration or HTML <META> tag.
                var sd = SniffEncoding();
                if(sd != null) {
                    this.m_decoder = sd;
                }
            }

            // Reset to get ready for Read()
            this.stm.Seek(0, SeekOrigin.Begin);
            this.pos = this.used = 0;
            // skip bom
            if(bom > 0) {
                stm.Read(this.rawBuffer, 0, bom);
            }
            this.rawPos = this.rawUsed = 0;
        }
開發者ID:roomaroo,項目名稱:coapp.powershell,代碼行數:36,代碼來源:SgmlParseException.cs


注:本文中的System.Stream.Read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。