当前位置: 首页>>代码示例>>C#>>正文


C# IO.Stream类代码示例

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


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


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