当前位置: 首页>>代码示例>>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;未经允许,请勿转载。