C# MemoryStream.Flush的代码示例
通过代码示例来学习C# MemoryStream.Flush方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.Flush是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.Flush() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.Flush() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.Flush的代码示例1 - SaveFileFormat()
using System.IO; ///
/// Saves the /// The format instance of the file being saved /// The name of the file /// The Alignment used for compression. Used for Yaz0 compression type. /// Toggle for showing compression dialog ///as a file from the given /// public static void SaveFileFormat(IFileFormat FileFormat, string FileName, bool EnableDialog = true, string DetailsLog = "") { //These always get created on loading a file,however not on creating a new file if (FileFormat.IFileInfo == null) throw new System.NotImplementedException("Make sure to impliment a IFileInfo instance if a format is being created!"); Cursor.Current = Cursors.WaitCursor; FileFormat.FilePath = FileName; string compressionLog = ""; if (FileFormat.IFileInfo.FileIsCompressed || FileFormat.IFileInfo.InArchive || Path.GetExtension(FileName) == ".szs" || Path.GetExtension(FileName) == ".sbfres" || Path.GetExtension(FileName) == ".mc") { //Todo find more optmial way to handle memory with files in archives //Also make compression require streams var mem = new System.IO.MemoryStream(); FileFormat.Save(mem); mem = new System.IO.MemoryStream(mem.ToArray()); FileFormat.IFileInfo.DecompressedSize = (uint)mem.Length; var finalStream = CompressFileFormat( FileFormat.IFileInfo.FileCompression, mem, FileFormat.IFileInfo.FileIsCompressed, FileFormat.IFileInfo.Alignment, FileName, EnableDialog); compressionLog = finalStream.Item2; Stream compressionStream = finalStream.Item1; FileFormat.IFileInfo.CompressedSize = (uint)compressionStream.Length; compressionStream.ExportToFile(FileName); DetailsLog += "\n" + SatisfyFileTables(FileFormat, FileName, compressionStream, FileFormat.IFileInfo.DecompressedSize, FileFormat.IFileInfo.CompressedSize, FileFormat.IFileInfo.FileIsCompressed); compressionStream.Flush(); compressionStream.Close(); } else { //Check if a stream is active and the file is beinng saved to the same opened file if (FileFormat is ISaveOpenedFileStream && FileFormat.FilePath == FileName && File.Exists(FileName)) { string savedPath = Path.GetDirectoryName(FileName); string tempPath = Path.Combine(savedPath, "tempST.bin"); //Save a temporary file first to not disturb the opened file using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { FileFormat.Save(fileStream); FileFormat.Unload(); //After saving is done remove the existing file File.Delete(FileName); //Now move and rename our temp file to the new file path File.Move(tempPath, FileName); FileFormat.Load(File.OpenRead(FileName)); var activeForm = LibraryGUI.GetActiveForm(); if (activeForm != null && activeForm is ObjectEditor) ((ObjectEditor)activeForm).ReloadArchiveFile(FileFormat); } } else { using (var fileStream = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { FileFormat.Save(fileStream); } } } if (EnableDialog) { if (compressionLog != string.Empty) MessageBox.Show($"File has been saved to {FileName}. Compressed time: {compressionLog}", "Save Notification"); else MessageBox.Show($"File has been saved to {FileName}", "Save Notification"); } // STSaveLogDialog.Show($"File has been saved to {FileName}", "Save Notification", DetailsLog); Cursor.Current = Cursors.Default; }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:100,代码来源:STFileSaver.cs
在SaveFileFormat()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例2 - GetDefaultImports()
using System.IO; // Internal for testing. internal static RazorSourceDocument GetDefaultImports() { using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, Encoding.UTF8)) { writer.WriteLine("@using System"); writer.WriteLine("@using System.Collections.Generic"); writer.WriteLine("@using System.Linq"); writer.WriteLine("@using System.Threading.Tasks"); writer.WriteLine("@using Microsoft.AspNetCore.Mvc"); writer.WriteLine("@using Microsoft.AspNetCore.Mvc.Rendering"); writer.WriteLine("@using Microsoft.AspNetCore.Mvc.ViewFeatures"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper
Html"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider"); writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor"); writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor"); writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor"); writer.Flush(); stream.Position = 0; return RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8); } }
开发者ID:aspnet,项目名称:Razor,代码行数:29,代码来源:MvcRazorTemplateEngine.cs
在GetDefaultImports()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例3 - WriteAsync()
using System.IO; ///
/// Write a Request to the stream. /// public async Task WriteAsync(Stream outStream, CancellationToken cancellationToken = default(CancellationToken)) { using (var memoryStream = new MemoryStream()) using (var writer = new BinaryWriter(memoryStream, Encoding.Unicode)) { // Format the request. ServerLogger.Log("Formatting request"); writer.Write(ProtocolVersion); writer.Write(Arguments.Count); foreach (var arg in Arguments) { cancellationToken.ThrowIfCancellationRequested(); arg.WriteToBinaryWriter(writer); } writer.Flush(); cancellationToken.ThrowIfCancellationRequested(); // Write the length of the request var length = checked((int)memoryStream.Length); // Back out if the request is > 1 MB if (memoryStream.Length > 0x100000) { ServerLogger.Log("Request is over 1MB in length, cancelling write"); throw new ArgumentOutOfRangeException(); } // Send the request to the server ServerLogger.Log("Writing length of request."); await outStream .WriteAsync(BitConverter.GetBytes(length), 0, 4, cancellationToken) .ConfigureAwait(false); ServerLogger.Log("Writing request of size {0}", length); // Write the request memoryStream.Position = 0; await memoryStream .CopyToAsync(outStream, bufferSize: length, cancellationToken: cancellationToken) .ConfigureAwait(false); } }
开发者ID:aspnet,项目名称:Razor,代码行数:47,代码来源:ServerRequest.cs
在WriteAsync()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例4 - WriteAsync()
using System.IO; public async Task WriteAsync(Stream outStream, CancellationToken cancellationToken) { using (var memoryStream = new MemoryStream()) using (var writer = new BinaryWriter(memoryStream, Encoding.Unicode)) { // Format the response ServerLogger.Log("Formatting Response"); writer.Write((int)Type); AddResponseBody(writer); writer.Flush(); cancellationToken.ThrowIfCancellationRequested(); // Send the response to the client // Write the length of the response var length = checked((int)memoryStream.Length); ServerLogger.Log("Writing response length"); // There is no way to know the number of bytes written to // the pipe stream. We just have to assume all of them are written. await outStream .WriteAsync(BitConverter.GetBytes(length), 0, 4, cancellationToken) .ConfigureAwait(false); // Write the response ServerLogger.Log("Writing response of size {0}", length); memoryStream.Position = 0; await memoryStream .CopyToAsync(outStream, bufferSize: length, cancellationToken: cancellationToken) .ConfigureAwait(false); } }
开发者ID:aspnet,项目名称:Razor,代码行数:36,代码来源:ServerResponse.cs
在WriteAsync()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例5 - GenerateContent()
using System.IO; // Generates content of vmlDrawingPart1. internal static bool GenerateContent(VmlDrawingPart vmlDrawingPart, XLWorksheet xlWorksheet) { using (var ms = new MemoryStream()) using (var stream = vmlDrawingPart.GetStream(FileMode.OpenOrCreate)) { XLWorkbook.CopyStream(stream, ms); stream.Position = 0; var writer = new XmlTextWriter(stream, Encoding.UTF8); writer.WriteStartElement("xml"); // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.vml.shapetype?view=openxml-2.8.1#remarks // This element defines a shape template that can be used to create other shapes. // Shapetype is identical to the shape element(§14.1.2.19) except it cannot reference another shapetype element. // The type attribute shall not be used with shapetype. // Attributes defined in the shape override any that appear in the shapetype positioning attributes // (such as top, width, z-index, rotation, flip) are not passed to a shape from a shapetype. // To use this element, create a shapetype with a specific id attribute. // Then create a shape and reference the shapetype's id using the type attribute. new Vml.Shapetype( new Vml.Stroke { JoinStyle = Vml.StrokeJoinStyleValues.Miter }, new Vml.Path { AllowGradientShape = true, ConnectionPointType = ConnectValues.Rectangle } ) { Id = XLConstants.Comment.ShapeTypeId, CoordinateSize = "21600,21600", OptionalNumber = 202, EdgePath = "m,l,21600r21600,l21600,xe", } .WriteTo(writer); var cellWithComments = xlWorksheet.Internals.CellsCollection.GetCells(c => c.HasComment); var hasAnyVmlElements = false; foreach (var c in cellWithComments) { GenerateCommentShape(c).WriteTo(writer); hasAnyVmlElements |= true; } if (ms.Length > 0) { ms.Position = 0; var xdoc = XDocumentExtensions.Load(ms); xdoc.Root.Elements().ForEach(e => writer.WriteRaw(e.ToString())); hasAnyVmlElements |= xdoc.Root.HasElements; } writer.WriteEndElement(); writer.Flush(); writer.Close(); return hasAnyVmlElements; } }
开发者ID:ClosedXML,项目名称:ClosedXML,代码行数:58,代码来源:VmlDrawingPartWriter.cs
在GenerateContent()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例6 - ToTextAll()
using System.IO; public static string ToTextAll
(IEnumerable records, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null) where TRec : class { if (records == null) return null; if (typeof(DataTable).IsAssignableFrom(typeof(TRec))) { StringBuilder csv = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(dt); } return csv.ToString(); } else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec))) { StringBuilder csv = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(dt); } return csv.ToString(); } using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVWriter (writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { parser.Write(records); writer.Flush(); stream.Position = 0; return reader.ReadToEnd(); } }
开发者ID:Cinchoo,项目名称:ChoETL,代码行数:47,代码来源:ChoCSVWriter.cs
在ToTextAll()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例7 - ToTextAll()
using System.IO; public static string ToTextAll
(IEnumerable records, ChoFixedLengthRecordConfiguration configuration = null, TraceSwitch traceSwitch = null) where TRec : class { if (records == null) return null; if (typeof(DataTable).IsAssignableFrom(typeof(TRec))) { StringBuilder text = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoFixedLengthWriter(text, configuration)) w.Write(dt); } return text.ToString(); } else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec))) { StringBuilder text = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoFixedLengthWriter(text, configuration)) w.Write(dt); } return text.ToString(); } using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoFixedLengthWriter (writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { parser.Write(records); writer.Flush(); stream.Position = 0; return reader.ReadToEnd(); } }
开发者ID:Cinchoo,项目名称:ChoETL,代码行数:47,代码来源:ChoFixedLengthWriter.cs
在ToTextAll()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Flush的代码示例8 - ToTextAll()
using System.IO; public static string ToTextAll
(IEnumerable records, ChoJSONRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string jsonPath = null) { if (records == null) return null; if (typeof(DataTable).IsAssignableFrom(typeof(TRec))) { StringBuilder json = new StringBuilder(); foreach (var dt in records.Take(1)) { using (var w = new ChoJSONWriter(json, configuration)) { w.Write(dt); } } return json.ToString(); } else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec))) { StringBuilder json = new StringBuilder(); foreach (var dt in records.Take(1)) { using (var w = new ChoJSONWriter(json, configuration)) { w.Write(dt); } } return json.ToString(); } using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoJSONWriter (writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { parser.Configuration.JSONPath = jsonPath; parser.Write(records); parser.Close(); writer.Flush(); stream.Position = 0; return reader.ReadToEnd(); } }
开发者ID:Cinchoo,项目名称:ChoETL,代码行数:53,代码来源:ChoJSONWriter.cs
在ToTextAll()方法中,MemoryStream的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.Flush方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。