C# MemoryStream.CopyTo的代码示例
通过代码示例来学习C# MemoryStream.CopyTo方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.CopyTo是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.CopyTo() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.CopyTo() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.CopyTo的代码示例1 - RunPrefetchPacksDeserializerTest()
using System.IO; private void RunPrefetchPacksDeserializerTest(int packCount, bool withIndexes) { using (MemoryStream ms = new MemoryStream()) { long[] packTimestamps = Enumerable.Range(0, packCount).Select(x => (long)x).ToArray(); // Write the data to the memory stream. this.WriteToSpecs(ms, packTimestamps, withIndexes); ms.Position = 0; Dictionary
>> receivedPacksAndIndexes = new Dictionary >>(); foreach (PrefetchPacksDeserializer.PackAndIndex pack in new PrefetchPacksDeserializer(ms).EnumeratePacks()) { List > packsAndIndexesByUniqueId; if (!receivedPacksAndIndexes.TryGetValue(pack.UniqueId, out packsAndIndexesByUniqueId)) { packsAndIndexesByUniqueId = new List >(); receivedPacksAndIndexes.Add(pack.UniqueId, packsAndIndexesByUniqueId); } using (MemoryStream packContent = new MemoryStream()) using (MemoryStream idxContent = new MemoryStream()) { pack.PackStream.CopyTo(packContent); byte[] packData = packContent.ToArray(); packData.ShouldMatchInOrder(PackForTimestamp(pack.Timestamp)); packsAndIndexesByUniqueId.Add(Tuple.Create("pack", pack.Timestamp)); if (pack.IndexStream != null) { pack.IndexStream.CopyTo(idxContent); byte[] idxData = idxContent.ToArray(); idxData.ShouldMatchInOrder(IndexForTimestamp(pack.Timestamp)); packsAndIndexesByUniqueId.Add(Tuple.Create("idx", pack.Timestamp)); } } } receivedPacksAndIndexes.Count.ShouldEqual(packCount, "UniqueId count"); foreach (List > groupedByUniqueId in receivedPacksAndIndexes.Values) { if (withIndexes) { groupedByUniqueId.Count.ShouldEqual(2, "Both Pack and Index for UniqueId"); // Should only contain 1 index file groupedByUniqueId.ShouldContainSingle(x => x.Item1 == "idx"); } // should only contain 1 pack file groupedByUniqueId.ShouldContainSingle(x => x.Item1 == "pack"); groupedByUniqueId.Select(x => x.Item2).Distinct().Count().ShouldEqual(1, "Same timestamps for a uniqueId"); } } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:60,代码来源:PrefetchPacksDeserializerTests.cs
在RunPrefetchPacksDeserializerTest()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例2 - Inflate()
using System.IO; static ByteVector Inflate (ByteVector data) { using (var out_stream = new MemoryStream ()) using (var input = new MemoryStream (data.Data)) { input.Seek (2, SeekOrigin.Begin); // First 2 bytes are properties deflate does not need (or handle) using (var zipstream = new DeflateStream (input, CompressionMode.Decompress)) { //zipstream.CopyTo (out_stream); Cleaner with .NET 4 byte[] buffer = new byte[1024]; int written_bytes; while ((written_bytes = zipstream.Read (buffer, 0, 1024)) > 0) out_stream.Write (buffer, 0, written_bytes); return new ByteVector (out_stream.ToArray ()); } } }
开发者ID:mono,项目名称:taglib-sharp,代码行数:19,代码来源:File.cs
在Inflate()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例3 - AddBoardsToSet()
using System.IO; public void AddBoardsToSet(List
FileList, ProgressLog Logger , bool fixgroup = true, bool forcezerowidth = false) { Logger.PushActivity("AddBoardsToSet"); foreach (var a in FileList) { Logger.AddString(String.Format("adding {0}", a)); BoardSide aSide = BoardSide.Unknown; BoardLayer aLayer = BoardLayer.Unknown; string ext = Path.GetExtension(a); if (ext == ".zip") { using (ZipFile zip1 = ZipFile.Read(a)) { foreach (ZipEntry e in zip1) { MemoryStream MS = new MemoryStream(); if (e.IsDirectory == false) { // e.Extract(MS); // MS.Seek(0, SeekOrigin.Begin); Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer); if (aLayer == BoardLayer.Outline) hasgko = true; // AddFileStream(MS, e.FileName, drillscaler); } } } } else { Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer); } if (aLayer == BoardLayer.Outline) hasgko = true; } foreach (var a in FileList) { if (Logger != null) Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a))); string ext = Path.GetExtension(a); if (ext == ".zip") { using (ZipFile zip1 = ZipFile.Read(a)) { foreach (ZipEntry e in zip1) { MemoryStream MS = new MemoryStream(); if (e.IsDirectory == false) { if (Logger != null) Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName))); e.Extract(MS); MS.Seek(0, SeekOrigin.Begin); AddFileToSet(MS, e.FileName, Logger, 1, forcezerowidth); } } } } else { try { MemoryStream MS2 = new MemoryStream(); FileStream FS = File.OpenRead(a); FS.CopyTo(MS2); MS2.Seek(0, SeekOrigin.Begin); AddFileToSet(MS2, a, Logger,1, forcezerowidth); } catch (Exception E) { Logger.AddString(String.Format("Failed to add file! {0},{1}", a, E)); } } } if (fixgroup) { if (Logger != null) Logger.AddString("Checking for common file format mistakes."); FixEagleDrillExportIssues(Logger); CheckRelativeBoundingBoxes(Logger); CheckForOutlineFiles(Logger); CheckRelativeBoundingBoxes(Logger); } Logger.PopActivity(); }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:90,代码来源:ImageCreator.cs
在AddBoardsToSet()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例4 - AddFile()
using System.IO; public void AddFile(ProgressLog log, string filename, double drillscaler = 1.0) { string[] filesplit = filename.Split('.'); string ext = filesplit[filesplit.Count() - 1].ToLower(); if (ext == "zip") { using (ZipFile zip1 = ZipFile.Read(filename)) { foreach (ZipEntry e in zip1) { MemoryStream MS = new MemoryStream(); if (e.IsDirectory == false) { e.Extract(MS); MS.Seek(0, SeekOrigin.Begin); AddFileStream(log, MS, e.FileName, drillscaler); } } } return; } MemoryStream MS2 = new MemoryStream(); FileStream FS = File.OpenRead(filename); FS.CopyTo(MS2); MS2.Seek(0, SeekOrigin.Begin); AddFileStream(log, MS2, filename, drillscaler); }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:34,代码来源:LoadedStuff.cs
在AddFile()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例5 - AddBoardsToSet()
using System.IO; public void AddBoardsToSet(List
FileList, bool fixgroup = true, ProgressLog Logger = null) { foreach (var a in FileList) { BoardSide aSide = BoardSide.Unknown; BoardLayer aLayer = BoardLayer.Unknown; string ext = Path.GetExtension(a); if (ext == ".zip") { using (ZipFile zip1 = ZipFile.Read(a)) { foreach (ZipEntry e in zip1) { MemoryStream MS = new MemoryStream(); if (e.IsDirectory == false) { // e.Extract(MS); // MS.Seek(0, SeekOrigin.Begin); Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer); if (aLayer == BoardLayer.Outline) HasLoadedOutline = true; // AddFileStream(MS, e.FileName, drillscaler); } } } } else { Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer); } if (aLayer == BoardLayer.Outline) HasLoadedOutline = true; } foreach (var a in FileList) { if (Logger != null) Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a))); string ext = Path.GetExtension(a); if (ext == ".zip") { using (ZipFile zip1 = ZipFile.Read(a)) { foreach (ZipEntry e in zip1) { MemoryStream MS = new MemoryStream(); if (e.IsDirectory == false) { if (Logger != null) Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName))); e.Extract(MS); MS.Seek(0, SeekOrigin.Begin); AddFileToSet(MS, e.FileName, Logger); } } } } else { MemoryStream MS2 = new MemoryStream(); FileStream FS = File.OpenRead(a); FS.CopyTo(MS2); MS2.Seek(0, SeekOrigin.Begin); AddFileToSet(MS2, a, Logger); } } if (fixgroup) { if (Logger != null) Logger.AddString("Checking for common file format mistakes."); FixEagleDrillExportIssues(Logger); CheckRelativeBoundingBoxes(Logger); CheckForOutlineFiles(Logger); CheckRelativeBoundingBoxes(Logger); } }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:79,代码来源:SickOfBeige.cs
在AddBoardsToSet()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例6 - ExecuteCore()
using System.IO; private int ExecuteCore(RazorConfiguration configuration, string projectDirectory, string outputFilePath, string[] assemblies) { outputFilePath = Path.Combine(projectDirectory, outputFilePath); var metadataReferences = new MetadataReference[assemblies.Length]; for (var i = 0; i < assemblies.Length; i++) { metadataReferences[i] = Parent.AssemblyReferenceProvider(assemblies[i], default(MetadataReferenceProperties)); } var engine = RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b => { b.Features.Add(new DefaultMetadataReferenceFeature() { References = metadataReferences }); b.Features.Add(new CompilationTagHelperFeature()); b.Features.Add(new DefaultTagHelperDescriptorProvider()); b.Features.Add(new ComponentTagHelperDescriptorProvider()); }); var feature = engine.Engine.Features.OfType
().Single(); var tagHelpers = feature.GetDescriptors(); using (var stream = new MemoryStream()) { Serialize(stream, tagHelpers); stream.Position = 0; var newHash = Hash(stream); var existingHash = Hash(outputFilePath); if (!HashesEqual(newHash, existingHash)) { stream.Position = 0; using (var output = File.Open(outputFilePath, FileMode.Create)) { stream.CopyTo(output); } } } return ExitCodeSuccess; }
开发者ID:aspnet,项目名称:Razor,代码行数:44,代码来源:DiscoverCommand.cs
在ExecuteCore()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例7 - Read()
using System.IO; public override Stream Read() { // Act like a file and have a UTF8 BOM. var preamble = Encoding.UTF8.GetPreamble(); var contentBytes = Encoding.UTF8.GetBytes(Content); var buffer = new byte[preamble.Length + contentBytes.Length]; preamble.CopyTo(buffer, 0); contentBytes.CopyTo(buffer, preamble.Length); var stream = new MemoryStream(buffer); return stream; }
开发者ID:aspnet,项目名称:Razor,代码行数:15,代码来源:TestRazorProjectItem.cs
在Read()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.CopyTo的代码示例8 - CanCopyAutoFilterToNewSheetOnNewWorkbook()
using System.IO; [Test] public void CanCopyAutoFilterToNewSheetOnNewWorkbook() { using (var ms1 = new MemoryStream()) using (var ms2 = new MemoryStream()) { using (var wb1 = new XLWorkbook()) using (var wb2 = new XLWorkbook()) { var ws = wb1.Worksheets.Add("AutoFilter"); ws.Cell("A1").Value = "Names"; ws.Cell("A2").Value = "John"; ws.Cell("A3").Value = "Hank"; ws.Cell("A4").Value = "Dagny"; ws.RangeUsed().SetAutoFilter(); wb1.SaveAs(ms1); ws.CopyTo(wb2, ws.Name); wb2.SaveAs(ms2); } using (var wb2 = new XLWorkbook(ms2)) { Assert.IsTrue(wb2.Worksheets.First().AutoFilter.IsEnabled); } } }
开发者ID:ClosedXML,项目名称:ClosedXML,代码行数:31,代码来源:AutoFilterTests.cs
在CanCopyAutoFilterToNewSheetOnNewWorkbook()方法中,MemoryStream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.CopyTo方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。