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


C# Stream类代码示例

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


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


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