• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IO.Stream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.IO.Stream的典型用法代码示例。如果您正苦于以下问题:C# Stream类的具体用法?C# Stream怎么用?C# Stream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Stream类属于System.IO命名空间,在下文中一共展示了Stream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateText

        public SourceText CreateText(Stream stream, Encoding defaultEncoding, CancellationToken cancellationToken = default(CancellationToken))
        {
            // this API is for a case where user wants us to figure out encoding from the given stream.
            // if defaultEncoding is given, we will use it if we couldn't figure out encoding used in the stream ourselves.
            Debug.Assert(stream != null);
            Debug.Assert(stream.CanSeek);
            Debug.Assert(stream.CanRead);

            if (defaultEncoding == null)
            {
                // Try UTF-8
                try
                {
                    return CreateTextInternal(stream, s_throwingUtf8Encoding, cancellationToken);
                }
                catch (DecoderFallbackException)
                {
                    // Try Encoding.Default
                    defaultEncoding = Encoding.Default;
                }
            }

            try
            {
                return CreateTextInternal(stream, defaultEncoding, cancellationToken);
            }
            catch (DecoderFallbackException)
            {
                return null;
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:31,代码来源:EditorTextFactoryService.cs


示例2: Metafile

		// Usually called when cloning images that need to have
		// not only the handle saved, but also the underlying stream
		// (when using MS GDI+ and IStream we must ensure the stream stays alive for all the life of the Image)
		internal Metafile (IntPtr ptr, Stream stream)
		{
			// under Win32 stream is owned by SD/GDI+ code
			if (GDIPlus.RunningOnWindows ())
				this.stream = stream;
			nativeObject = ptr;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:Metafile.cs


示例3: Save

        public void Save(Stream output)
        {
            BinaryWriter writer = new BinaryWriter(output);

            writer.Write(this.version);
            writer.Write((int)0);
            writer.Write((int)0);

            // Double the string length since it's UTF16
            writer.Write((byte)(this.partName.Length * 2));
            MadScience.StreamHelpers.WriteStringUTF16(output, false, this.partName);

            writer.Write(this.blendType);
            this.blendTgi.Save(output);

            writer.Write((uint)this.geomBoneEntries.Count);
            for (int i = 0; i < this.geomBoneEntries.Count; i++)
            {
                this.geomBoneEntries[i].Save(output);
            }

            uint tgiOffset = (uint)output.Position - 8;
            // Why is this +12?  I dunno. :)
            this.keytable.size = 8;
            this.keytable.Save(output);
            output.Seek(4, SeekOrigin.Begin);
            writer.Write(tgiOffset);
            writer.Write(this.keytable.size);

            writer = null;
        }
开发者ID:ellacharmed,项目名称:madscientistproductions,代码行数:31,代码来源:FacialBlend.cs


示例4: SetOutput

 protected void SetOutput(Stream stream, bool ownsStream, Encoding encoding)
 {
     _stream = stream;
     _ownsStream = ownsStream;
     _offset = 0;
     _encoding = encoding;
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:XmlStreamNodeWriter.cs


示例5: ComputeHash

        /// <summary>
        /// Compute a hash from the content of a stream and restore the position.
        /// </summary>
        /// <remarks>
        /// Modified FNV Hash in C#
        /// http://stackoverflow.com/a/468084
        /// </remarks>
        internal static int ComputeHash(Stream stream)
        {
            System.Diagnostics.Debug.Assert(stream.CanSeek);

            unchecked
            {
                const int p = 16777619;
                var hash = (int)2166136261;

                var prevPosition = stream.Position;
                stream.Position = 0;

                var data = new byte[1024];
                int length;
                while((length = stream.Read(data, 0, data.Length)) != 0)
                {
                    for (var i = 0; i < length; i++)
                        hash = (hash ^ data[i]) * p;
                }

                // Restore stream position.
                stream.Position = prevPosition;

                hash += hash << 13;
                hash ^= hash >> 7;
                hash += hash << 3;
                hash ^= hash >> 17;
                hash += hash << 5;
                return hash;
            }
        }
开发者ID:Cardanis,项目名称:MonoGame,代码行数:38,代码来源:Hash.cs


示例6: ReadProp

 public override void ReadProp(Stream input, bool array)
 {
     this.R = input.ReadF32();
     this.G = input.ReadF32();
     this.B = input.ReadF32();
     this.A = input.ReadF32();
 }
开发者ID:VFedyk,项目名称:sporemaster,代码行数:7,代码来源:ColorRGBAProperty.cs


示例7: WriteToStream

 public static void WriteToStream(Image img, Stream stream)
 {
     IntPtr point = img.gdImageStructPtr;
     DLLImports.gdImageStruct gdImageStruct = Marshal.PtrToStructure<DLLImports.gdImageStruct>(point);
     var wrapper = new gdStreamWrapper(stream);
     DLLImports.gdImageJpegCtx(ref gdImageStruct, ref wrapper.IOCallbacks);
 }
开发者ID:iliveoncaffiene,项目名称:corefxlab,代码行数:7,代码来源:Jpg.cs


示例8: StreamToXml

 public static XmlDocument StreamToXml(Stream stream)
 {
     var xmlDoc = new XmlDocument();
     var reader = new StreamReader(stream);
     xmlDoc.LoadXml(reader.ReadToEnd());
     return xmlDoc;
 }
开发者ID:renoir1220,项目名称:WeixinTest,代码行数:7,代码来源:WxMsgFactory.cs


示例9: StreamToMemory

        static MemoryStream StreamToMemory(Stream input)
        {
            byte[] buffer = new byte[1024];
            int count = 1024;
            MemoryStream output;

            // build a new stream
            if (input.CanSeek)
            {
                output = new MemoryStream((int)input.Length);
            }
            else
            {
                output = new MemoryStream();
            }

            // iterate stream and transfer to memory stream
            do
            {
                count = input.Read(buffer, 0, count);
                if (count == 0)
                    break; // TODO: might not be correct. Was : Exit Do
                output.Write(buffer, 0, count);
            } while (true);

            // rewind stream
            output.Position = 0;

            // pass back
            return output;
        }
开发者ID:btolbert,项目名称:test-commerce,代码行数:31,代码来源:ImageResult.cs


示例10: LimitedInputStream

		internal LimitedInputStream(
			Stream inStream,
			int limit)
		{
			this._in = inStream;
			this._limit = limit;
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:7,代码来源:LimitedInputStream.cs


示例11: Read

        public void Read(Stream inputStream)
        {
            BinaryReader reader = new BinaryReader(inputStream, Encoding.UTF8, true);
            int magicNumber = reader.ReadInt32();
            int version = reader.ReadInt32(); // GZ 2, TPP 3
            int endianess = reader.ReadInt32(); // LE, BE
            int entryCount = reader.ReadInt32();
            int valuesOffset = reader.ReadInt32();
            int keysOffset = reader.ReadInt32();

            inputStream.Position = valuesOffset;
            Dictionary<int, LangEntry> offsetEntryDictionary = new Dictionary<int, LangEntry>();
            for (int i = 0; i < entryCount; i++)
            {
                int valuePosition = (int)inputStream.Position - valuesOffset;
                short valueConstant = reader.ReadInt16();
                Debug.Assert(valueConstant == 1);
                string value = reader.ReadNullTerminatedString();
                offsetEntryDictionary.Add(valuePosition, new LangEntry
                {
                    Value = value
                });
            }
            
            inputStream.Position = keysOffset;
            for (int i = 0; i < entryCount; i++)
            {
                uint key = reader.ReadUInt32();
                int offset = reader.ReadInt32();

                offsetEntryDictionary[offset].Key = key;
            }

            Entries = offsetEntryDictionary.Values.ToList();
        }
开发者ID:kkkkyue,项目名称:FoxEngine.TranslationTool,代码行数:35,代码来源:LangFile.cs


示例12: AllowRead

		public override ReadVetoResult AllowRead(string key, Stream data, RavenJObject metadata, ReadOperation operation)
		{
			RavenJToken value;
			if (metadata.TryGetValue("Raven-Delete-Marker", out value))
				return ReadVetoResult.Ignore;
			return ReadVetoResult.Allowed;
		}
开发者ID:neiz,项目名称:ravendb,代码行数:7,代码来源:HideVirtuallyDeletedAttachmentsReadTrigger.cs


示例13: BundleFetchConnection

        public BundleFetchConnection(Transport transportBundle, Stream src)
        {
            transport = transportBundle;
            bin = new BufferedStream(src, IndexPack.BUFFER_SIZE);
            try
            {
                switch (readSignature())
                {
                    case 2:
                        readBundleV2();
                        break;

                    default:
                        throw new TransportException(transport.Uri, "not a bundle");
                }
            }
            catch (TransportException)
            {
                Close();
                throw;
            }
            catch (IOException err)
            {
                Close();
                throw new TransportException(transport.Uri, err.Message, err);
            }
        }
开发者ID:georgeck,项目名称:GitSharp,代码行数:27,代码来源:BundleFetchConnection.cs


示例14: Load

 public static AcmeRegistration Load(Stream s)
 {
     using (var r = new StreamReader(s))
     {
         return JsonConvert.DeserializeObject<AcmeRegistration>(r.ReadToEnd());
     }
 }
开发者ID:jagbarcelo,项目名称:ACMESharp,代码行数:7,代码来源:AcmeRegistration.cs


示例15: Save

 public void Save(Stream s)
 {
     using (var w = new StreamWriter(s))
     {
         w.Write(JsonConvert.SerializeObject(this, Formatting.Indented));
     }
 }
开发者ID:jagbarcelo,项目名称:ACMESharp,代码行数:7,代码来源:AcmeRegistration.cs


示例16: ComputeFileHash

 internal static byte[] ComputeFileHash(Stream fileStream)
 {
     using (var sha1 = new SHA1CryptoServiceProvider())
     {
         return sha1.ComputeHash(fileStream);
     }
 }
开发者ID:AnchoretTeam,项目名称:AppUpdate,代码行数:7,代码来源:FileHashHelper.cs


示例17: LoadSchema

 private static XmlSchemaSet LoadSchema(Stream xsd)
 {
     var reader = XmlReader.Create(xsd);
     var set = new XmlSchemaSet();
     set.Add(null, reader);
     return set;
 }
开发者ID:markovcd,项目名称:Mapper,代码行数:7,代码来源:XmlValidator.cs


示例18: AddToArchive

        private static string AddToArchive(string entryName, Stream inputStream, ZipArchive zipArchive, string hashName)
        {
            var entry = zipArchive.CreateEntry(entryName);

            HashAlgorithm hashAlgorithm = null;
            BinaryWriter zipEntryWriter = null;
            try
            {
                hashAlgorithm = HashAlgorithm.Create(hashName);
                zipEntryWriter = new BinaryWriter(entry.Open());

                var readBuffer = new byte[StreamReadBufferSize];
                int bytesRead;
                while ((bytesRead = inputStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    zipEntryWriter.Write(readBuffer, 0, bytesRead);
                    hashAlgorithm.TransformBlock(readBuffer, 0, bytesRead, readBuffer, 0);
                }
                hashAlgorithm.TransformFinalBlock(readBuffer, 0, 0);

                var hashHexStringBuilder = new StringBuilder();
                foreach (byte hashByte in hashAlgorithm.Hash)
                {
                    hashHexStringBuilder.Append(hashByte.ToString("x2"));
                }

                return hashHexStringBuilder.ToString();
            }
            finally
            {
                hashAlgorithm.SafeDispose();
                zipEntryWriter.SafeDispose();
            }
        }
开发者ID:GalenHealthcare,项目名称:Galen.Ef.Deployer,代码行数:34,代码来源:ZipUtility.cs


示例19: ReadOpcode

            public override IOpcode ReadOpcode(Stream stream)
            {
                int contourCount = ReadUnsignedByte(stream);

                //extended count
                if (contourCount == 0)
                {
                    contourCount = 256 + ReadUnsignedShort(stream);
                }

                for (int i = 0; i < contourCount; i++)
                {
                    //each contour has a list of points
                    int pointsCount = ReadUnsignedByte(stream);

                    //points extended count
                    if (pointsCount == 0)
                    {
                        pointsCount = 256 + ReadUnsignedShort(stream);
                    }

                    //first vertex
                    ReadSignedShort(stream);
                    ReadSignedShort(stream);

                    for (int j = 0; j < pointsCount; j++)
                    {
                        //vertex(j)
                        ReadSignedShort(stream);
                        ReadSignedShort(stream);
                    }
                }

                return new DrawContourSetShort();
            }
开发者ID:ElAleyo,项目名称:DwfTools,代码行数:35,代码来源:DrawContourSetShort.cs


示例20: Send

        public void Send(string toEmail, string subject, string body, Stream stream, string fileName)
        {
            SmtpClient smtp = new SmtpClient
            {
                Host = SmtpServer,
                Port = SmtpPort,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(FromEmail, Password)
            };

            using (MailMessage message = new MailMessage(FromEmail, toEmail))
            {
                message.Subject = subject;
                message.Body = body;

                if (stream != null)
                {
                    Attachment attachment = new Attachment(stream, fileName);
                    message.Attachments.Add(attachment);
                }

                smtp.Send(message);
            }
        }
开发者ID:yoykiee,项目名称:ShareX,代码行数:26,代码来源:Email.cs



注:本文中的System.IO.Stream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.StreamReader类代码示例发布时间:2022-05-26
下一篇:
C# IO.RenamedEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap