本文整理汇总了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))
};
}
}
}
示例2: ReadStream
private static string ReadStream(Stream stream)
{
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
示例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;
}
示例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;
}
示例5: GetSymbolReader
public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream)
{
Mixin.CheckModule (module);
Mixin.CheckStream (symbolStream);
return new PdbReader (Disposable.NotOwned (symbolStream));
}
示例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;
}
示例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;
}
示例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 & 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);
}
示例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;
}
示例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;
}
}
}
}
示例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]));
}
示例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;
}
示例13: SaveDrawing
public static void SaveDrawing(Drawing drawing, Stream stream)
{
using (var writer = XmlWriter.Create(stream, XmlSettings))
{
SaveDrawing(drawing, writer);
}
}
示例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));
}
示例15: UpdateMainListFromStream
private void UpdateMainListFromStream(Stream s)
{
using (s)
{
_mainList = ParserFactory.ParseMainListData(s);
}
}