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

C# Stream类代码示例

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

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



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

示例1: UploadImage

        private static S3File UploadImage(string key, Stream inputStream)
        {
            var s3Config = new AmazonS3Config() { ServiceURL = "http://" + _s3_bucket_region };
            using (var cli = new AmazonS3Client(
                _s3_access_key,
                _s3_secret_access_key,
                s3Config))
            {
                PutObjectRequest req = new PutObjectRequest()
                {
                    BucketName = _s3_bucket_name,
                    ContentType = "image/jpg",
                    InputStream = inputStream,
                    Key = key,
                    CannedACL = S3CannedACL.PublicRead
                };

                var response = cli.PutObject(req);
                if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new Exception("s3: upload failed.");
                }
                else
                {
                    return new S3File()
                    {
                        Key = key,
                        Url = HttpUtility.HtmlEncode(
                            String.Format("http://{0}.{1}/{2}", _s3_bucket_name, _s3_bucket_region, key))
                    };
                }
            }
        }
开发者ID:teo-mateo,项目名称:sdc,代码行数:33,代码来源:S3.cs


示例2: ReadStream

 private static string ReadStream(Stream stream)
 {
     using (var reader = new StreamReader(stream, Encoding.UTF8))
     {
         return reader.ReadToEnd();
     }
 }
开发者ID:ChrisMissal,项目名称:stripe.net,代码行数:7,代码来源:Requestor.cs


示例3: IntPtrCopy

		public static int IntPtrCopy(IntPtr source, Stream dest, int length)
		{
			var buffer = new Byte[length];
			Marshal.Copy(source, buffer, 0, length);
			dest.Write(buffer, 0, length);
			return length;
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:7,代码来源:RdcBufferTools.cs


示例4: MockClientHttpResponse

 /// <summary>
 /// Creates a new instance of <see cref="MockClientHttpResponse"/>.
 /// </summary>
 /// <param name="body">The body of the response as a stream.</param>
 /// <param name="headers">The response headers.</param>
 /// <param name="statusCode">The response status code.</param>
 /// <param name="statusDescription">The response status description.</param>
 public MockClientHttpResponse(Stream body, HttpHeaders headers, HttpStatusCode statusCode, string statusDescription)
 {
     this.body = body;
     this.headers = headers;
     this.statusCode = statusCode;
     this.statusDescription = statusDescription;
 }
开发者ID:gabrielgreen,项目名称:spring-net-rest,代码行数:14,代码来源:MockClientHttpResponse.cs


示例5: GetSymbolReader

        public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream)
        {
            Mixin.CheckModule (module);
            Mixin.CheckStream (symbolStream);

            return new PdbReader (Disposable.NotOwned (symbolStream));
        }
开发者ID:jbevain,项目名称:cecil,代码行数:7,代码来源:PdbHelper.cs


示例6: UploadMessageAsync

        /// <inheritdoc/>
        public async Task<Uri> UploadMessageAsync(Stream content, DateTime expirationUtc, string contentType, string contentEncoding, IProgress<int> bytesCopiedProgress, CancellationToken cancellationToken = default(CancellationToken))
        {
            Requires.NotNull(content, "content");
            Requires.Range(expirationUtc > DateTime.UtcNow, "expirationUtc");

            string blobName = Utilities.CreateRandomWebSafeName(DesktopUtilities.BlobNameLength);
            if (expirationUtc < DateTime.MaxValue)
            {
                DateTime roundedUp = expirationUtc - expirationUtc.TimeOfDay + TimeSpan.FromDays(1);
                blobName = roundedUp.ToString("yyyy.MM.dd") + "/" + blobName;
            }

            var blob = this.container.GetBlockBlobReference(blobName);

            // Set metadata with the precise expiration time, although for efficiency we also put the blob into a directory
            // for efficient deletion based on approximate expiration date.
            if (expirationUtc < DateTime.MaxValue)
            {
                blob.Metadata["DeleteAfter"] = expirationUtc.ToString(CultureInfo.InvariantCulture);
            }

            blob.Properties.ContentType = contentType;
            blob.Properties.ContentEncoding = contentEncoding;

            await blob.UploadFromStreamAsync(content.ReadStreamWithProgress(bytesCopiedProgress), cancellationToken);
            return blob.Uri;
        }
开发者ID:AArnott,项目名称:IronPigeon,代码行数:28,代码来源:AzureBlobStorage.cs


示例7: UnzipFileHandler

        private UnzipCode UnzipFileHandler(string fileName, Stream fileStream)
        {
            fileName = fileName.ToLower();
            if (fileName.EndsWith(".cfg") ||
                fileName.EndsWith("local.ip") ||
                fileName.EndsWith("password") ||
                fileName.EndsWith(".bat") ||
                fileName.EndsWith(".settings"))
            {
                if (this.NeedUpdateConfigFiles)
                {
                    if (fileStream != null)
                    {
                        WriteFile(fileStream, this.destPath + "\\" + fileName);
                    }
                    return UnzipCode.Compare;
                }
                return UnzipCode.Ignore;
            }

            if (fileName.EndsWith("scada.update.exe") || 
                (fileName.EndsWith("scada.watch.exe") && this.UpdateByWatch) ||
                fileName.EndsWith("icsharpcode.sharpziplib.dll"))
            {
                Console.WriteLine("File <" + fileName + "> In use:!");
                UpdateLog.Instance().AddName(fileName + " <iu>");
                return UnzipCode.Ignore;
            }

            return UnzipCode.None;
        }
开发者ID:oisy,项目名称:scada,代码行数:31,代码来源:Updater.cs


示例8: OnAcquireLicense

        // called before MediaOpened is raised, and when the Media pipeline is building a topology
        protected override void OnAcquireLicense(Stream licenseChallenge, Uri licenseServerUri)
        {
            StreamReader objStreamReader = new StreamReader(licenseChallenge);
            challengeString = objStreamReader.ReadToEnd();

            // set License Server URL, based on whether there is an override
            Uri resolvedLicenseServerUri;
            if (LicenseServerUriOverride == null)
                resolvedLicenseServerUri = licenseServerUri;
            else
                resolvedLicenseServerUri = LicenseServerUriOverride;

            //SMFPlayer bug: converting & to &amp; in query string parameters. This line fixes it.
            resolvedLicenseServerUri = new Uri(System.Windows.Browser.HttpUtility.HtmlDecode(resolvedLicenseServerUri.AbsoluteUri));

            //construct HttpWebRequest to license server
            HttpWebRequest objHttpWebRequest = WebRequest.Create(resolvedLicenseServerUri) as HttpWebRequest;
            objHttpWebRequest.Method = "POST";
            objHttpWebRequest.ContentType = "application/xml";
            //The headers below are necessary so that error handling and redirects are handled properly via the Silverlight client.
            objHttpWebRequest.Headers["msprdrm_server_redirect_compat"] = "false";
            objHttpWebRequest.Headers["msprdrm_server_exception_compat"] = "false";

            if (AddAuthorizationToken)
            {                
                string token = Token;
                objHttpWebRequest.Headers["Authorization"] = token;   //e.g.: Bearer=urn:microsoft:azure:mediaservices:contentkeyidentifier=42b3ddc1-2b93-4813-b50b-af1ec3c9c771&urn%3aServiceAccessible=service&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fnimbusvoddev.accesscontrol.windows.net%2f&Audience=urn%3atest&ExpiresOn=1406385025&Issuer=http://testacs.com&HMACSHA256=kr1fHp0chSNaMcRimmENpk1E8LaS1ufknb8mR3xQhx4%3d
            }

            //  Initiate getting request stream  
            IAsyncResult objIAsyncResult = objHttpWebRequest.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), objHttpWebRequest);
        }
开发者ID:rhlbenjamin,项目名称:azure-media-services-samples,代码行数:33,代码来源:AMSBearerTokenLicenseAcquirer.cs


示例9: CheckMetaCharSetAndReEncode

        private string CheckMetaCharSetAndReEncode(Stream memStream, string html)
        {
            Match m = new Regex(@"<meta\s+.*?charset\s*=\s*(?<charset>[A-Za-z0-9_-]+)", RegexOptions.Singleline | RegexOptions.IgnoreCase).Match(html);
            if (m.Success)
            {
                string charset = m.Groups["charset"].Value.ToLower() ?? "iso-8859-1";
                if ((charset == "unicode") || (charset == "utf-16"))
                {
                    charset = "utf-8";
                }

                try
                {
                    Encoding metaEncoding = Encoding.GetEncoding(charset);
                    if (Encoding != metaEncoding)
                    {
                        memStream.Position = 0L;
                        StreamReader recodeReader = new StreamReader(memStream, metaEncoding);
                        html = recodeReader.ReadToEnd().Trim();
                        recodeReader.Close();
                    }
                }
                catch (ArgumentException)
                {
                }
            }

            return html;
        }
开发者ID:jooooel,项目名称:OpenGraph-Net,代码行数:29,代码来源:HttpDownloader.cs


示例10: using

        void IExtension.EndAppend(Stream stream, bool commit)
        {
            using (stream)
            {
                int len;
                if (commit && (len = (int)stream.Length) > 0)
                {
                    MemoryStream ms = (MemoryStream)stream;

                    if (buffer == null)
                    {   // allocate new buffer
                        buffer = ms.ToArray();
                    }
                    else
                    {   // resize and copy the data
                        // note: Array.Resize not available on CF
                        int offset = buffer.Length;
                        byte[] tmp = new byte[offset + len];
                        Buffer.BlockCopy(buffer, 0, tmp, 0, offset);
                        Buffer.BlockCopy(ms.GetBuffer(), 0, tmp, offset, len);
                        buffer = tmp;
                    }
                }
            }
        }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:25,代码来源:BufferExtension.cs


示例11: LogWriter

 public LogWriter(Stream stream, bool ownsStream)
 {
     _stream = stream;
     _ownsStream = ownsStream;
     BlockHelper.WriteBlock(_stream, BlockType.MagicBytes, new ArraySegment<byte>(Encoding.ASCII.GetBytes("TeraConnectionLog")));
     BlockHelper.WriteBlock(_stream, BlockType.Start, new ArraySegment<byte>(new byte[0]));
 }
开发者ID:ha-tam,项目名称:TeraDamageMeter,代码行数:7,代码来源:LogWriter.cs


示例12: Read

        /// <inheritdoc/>
        public Object Read(Stream mask0)
        {
            var result = new TrainingContinuation();
            var ins0 = new EncogReadHelper(mask0);
            EncogFileSection section;

            while ((section = ins0.ReadNextSection()) != null)
            {
                if (section.SectionName.Equals("CONT")
                    && section.SubSectionName.Equals("PARAMS"))
                {
                    IDictionary<String, String> paras = section.ParseParams();

                    foreach (String key  in  paras.Keys)
                    {
                        if (key.Equals("type", StringComparison.InvariantCultureIgnoreCase))
                        {
                            result.TrainingType = paras[key];
                        }
                        else
                        {
                            double[] list = EncogFileSection
                                .ParseDoubleArray(paras, key);
                            result.Put(key, list);
                        }
                    }
                }
            }

            return result;
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:32,代码来源:PersistTrainingContinuation.cs


示例13: SaveDrawing

 public static void SaveDrawing(Drawing drawing, Stream stream)
 {
     using (var writer = XmlWriter.Create(stream, XmlSettings))
     {
         SaveDrawing(drawing, writer);
     }
 }
开发者ID:ondrej11,项目名称:o106,代码行数:7,代码来源:DrawingSerializer.cs


示例14: WriteInt

 private static void WriteInt(Stream stream, int value)
 {
     stream.WriteByte((byte)(value));
     stream.WriteByte((byte)(value >> 8));
     stream.WriteByte((byte)(value >> 16));
     stream.WriteByte((byte)(value >> 24));
 }
开发者ID:dsmithson,项目名称:KnightwareCore,代码行数:7,代码来源:BitmapHelper.cs


示例15: UpdateMainListFromStream

 private void UpdateMainListFromStream(Stream s)
 {
     using (s)
     {
         _mainList = ParserFactory.ParseMainListData(s);
     }
 }
开发者ID:5nophilwu,项目名称:S1Nyan,代码行数:7,代码来源:DataService.cs


示例16: ReadByteAfterWhitespace

 protected int ReadByteAfterWhitespace(Stream s)
 {
     int buff = s.ReadByte();
     while (buff >= 0 && IsWhitespace(buff))
         buff = s.ReadByte();
     return buff;
 }
开发者ID:zleepy,项目名称:BlobDetector,代码行数:7,代码来源:PnmBase.cs


示例17: SerializeRequest

 public void SerializeRequest(Stream stm, XmlRpcRequest request)
 {
     var xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);
     xtw.WriteStartDocument();
     xtw.WriteStartElement(string.Empty, "methodCall", string.Empty);
     {
         var mappingActions = new MappingActions();
         mappingActions = GetTypeMappings(request.Mi, mappingActions);
         mappingActions = GetMappingActions(request.Mi, mappingActions);
         WriteFullElementString(xtw, "methodName", request.Method);
         if (request.Args.Length > 0 || UseEmptyParamsTag)
         {
             xtw.WriteStartElement("params");
             try
             {
                 if (!IsStructParamsMethod(request.Mi))
                     SerializeParams(xtw, request, mappingActions);
                 else
                     SerializeStructParams(xtw, request, mappingActions);
             }
             catch (XmlRpcUnsupportedTypeException ex)
             {
                 throw new XmlRpcUnsupportedTypeException(
                     ex.UnsupportedType,
                     string.Format(
                         "A parameter is of, or contains an instance of, type {0} which cannot be mapped to an XML-RPC type",
                         ex.UnsupportedType));
             }
             WriteFullEndElement(xtw);
         }
     }
     WriteFullEndElement(xtw);
     xtw.Flush();
 }
开发者ID:magicmonty,项目名称:xmlrpcnet,代码行数:34,代码来源:XmlRpcRequestSerializer.cs


示例18: BZip2DecoderStream

        /// <summary>
        /// Initializes a new instance of the BZip2DecoderStream class.
        /// </summary>
        /// <param name="stream">The compressed input stream.</param>
        /// <param name="ownsStream">Whether ownership of stream passes to the new instance.</param>
        public BZip2DecoderStream(Stream stream, Ownership ownsStream)
        {
            _compressedStream = stream;
            _ownsCompressed = ownsStream;

            _bitstream = new BigEndianBitStream(new BufferedStream(stream));

            // The Magic BZh
            byte[] magic = new byte[3];
            magic[0] = (byte)_bitstream.Read(8);
            magic[1] = (byte)_bitstream.Read(8);
            magic[2] = (byte)_bitstream.Read(8);
            if (magic[0] != 0x42 || magic[1] != 0x5A || magic[2] != 0x68)
            {
                throw new InvalidDataException("Bad magic at start of stream");
            }

            // The size of the decompression blocks in multiples of 100,000
            int blockSize = (int)_bitstream.Read(8) - 0x30;
            if (blockSize < 1 || blockSize > 9)
            {
                throw new InvalidDataException("Unexpected block size in header: " + blockSize);
            }

            blockSize *= 100000;

            _rleStream = new BZip2RleStream();
            _blockDecoder = new BZip2BlockDecoder(blockSize);
            _blockBuffer = new byte[blockSize];

            if (ReadBlock() == 0)
            {
                _eof = true;
            }
        }
开发者ID:alexcmd,项目名称:DiscUtils,代码行数:40,代码来源:BZip2DecoderStream.cs


示例19: TextureAtlas

		/// <summary>
		/// Creates texture atlas from stream.
		/// </summary>
		/// <param name="device"></param>
		public TextureAtlas ( RenderSystem rs, Stream stream, bool useSRgb = false )
		{
			var device = rs.Game.GraphicsDevice;

			using ( var br = new BinaryReader(stream) ) {
			
				br.ExpectFourCC("ATLS", "texture atlas");
				
				int count = br.ReadInt32();
				
				for ( int i=0; i<count; i++ ) {
					var element = new Element();
					element.Index	=	i;
					element.Name	=	br.ReadString();
					element.X		=	br.ReadInt32();
					element.Y		=	br.ReadInt32();
					element.Width	=	br.ReadInt32();
					element.Height	=	br.ReadInt32();

					elements.Add( element );
				}				

				int ddsFileLength	=	br.ReadInt32();
				
				var ddsImageBytes	=	br.ReadBytes( ddsFileLength );

				texture	=	new UserTexture( rs, ddsImageBytes, useSRgb );
			}


			dictionary	=	elements.ToDictionary( e => e.Name );
		}
开发者ID:demiurghg,项目名称:FusionEngine,代码行数:36,代码来源:TextureAtlas.cs


示例20: Load

 private static object Load(Stream stream)
 {
     var pc = new ParserContext();
     MethodInfo loadBamlMethod = typeof (XamlReader).GetMethod("LoadBaml",
         BindingFlags.NonPublic | BindingFlags.Static);
     return loadBamlMethod.Invoke(null, new object[] {stream, pc, null, false});
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:7,代码来源:Resources.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# StreamHandler类代码示例发布时间:2022-05-24
下一篇:
C# Strategy类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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