C# MemoryStream.Write的代码示例
通过代码示例来学习C# MemoryStream.Write方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.Write是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.Write() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.Write() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.Write的代码示例1 - CatchesFileNotFoundAfterFileDeleted()
using System.IO; [TestCase] [Category(CategoryConstants.ExceptionExpected)] public void CatchesFileNotFoundAfterFileDeleted() { MockFileSystemWithCallbacks fileSystem = new MockFileSystemWithCallbacks(); fileSystem.OnFileExists = (path) => true; fileSystem.OnOpenFileStream = (path, fileMode, fileAccess) => { if (fileAccess == FileAccess.Write) { return new MemoryStream(); } throw new FileNotFoundException(); }; MockHttpGitObjects httpObjects = new MockHttpGitObjects(); using (httpObjects.InputStream = new MemoryStream(this.validTestObjectFileContents)) { httpObjects.MediaType = GVFSConstants.MediaTypes.LooseObjectMediaType; GVFSGitObjects dut = this.CreateTestableGVFSGitObjects(httpObjects, fileSystem); dut.TryCopyBlobContentStream( ValidTestObjectFileSha1, new CancellationToken(), GVFSGitObjects.RequestSource.FileStreamCallback, (stream, length) => Assert.Fail("Should not be able to call copy stream callback")) .ShouldEqual(false); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:32,代码来源:GVFSGitObjectsTests.cs
在CatchesFileNotFoundAfterFileDeleted()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例2 - WriteLooseObject_DetectsDataNotCompressed()
using System.IO; [TestCase] public void WriteLooseObject_DetectsDataNotCompressed() { ITracer tracer = new MockTracer(); GVFSEnlistment enlistment = new MockGVFSEnlistment(); MockFileSystemWithCallbacks filesystem = new MockFileSystemWithCallbacks(); GVFSContext context = new GVFSContext(tracer, filesystem, null, enlistment); GitObjects gitObjects = new GVFSGitObjects(context, null); this.openedPaths.Clear(); filesystem.OnOpenFileStream = this.OnOpenFileStream; filesystem.OnFileExists = this.OnFileExists; bool foundException = false; try { using (Stream stream = new MemoryStream()) { stream.Write(new byte[] { 0, 1, 2, 3, 4 }, 0, 5); stream.Position = 0; gitObjects.WriteLooseObject(stream, EmptySha, true, new byte[128]); } } catch (RetryableException ex) { foundException = true; ex.Message.ShouldContain($"Requested object with hash {EmptySha} but received data that failed decompression."); } foundException.ShouldBeTrue("Failed to throw RetryableException"); this.openedPaths.Count.ShouldEqual(1, "Incorrect number of opened paths (one to write temp file)"); this.openedPaths[0].IndexOf(EmptySha.Substring(2)).ShouldBeAtMost(-1, "Should not have written to the loose object location"); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:37,代码来源:GitObjectsTests.cs
在WriteLooseObject_DetectsDataNotCompressed()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例3 - GetEmbeddedBitmap()
using System.IO; ///
/// Extracts the bitmap embedded into MSI (into Binary table). /// /// The session. /// The name on resource in the Binary table. ///public static Bitmap GetEmbeddedBitmap(this Session session, string binary) { try { using (var sql = session.Database.OpenView("select Data from Binary where Name = '" + binary + "'")) { sql.Execute(); using (var record = sql.Fetch()) using (var stream = record.GetStream(1)) using (var ms = new IO.MemoryStream()) { int Length = 256; var buffer = new Byte[Length]; int bytesRead = stream.Read(buffer, 0, Length); while (bytesRead > 0) { ms.Write(buffer, 0, bytesRead); bytesRead = stream.Read(buffer, 0, Length); } ms.Seek(0, IO.SeekOrigin.Begin); return (Bitmap)Bitmap.FromStream(ms); } } } catch { } return null; }
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:37,代码来源:Extensions.cs
在GetEmbeddedBitmap()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例4 - GetMSIBinaryStream()
using System.IO; ///
/// Gets the embedded MSI binary stream. /// /// The binary id. ///Stream instance public Stream GetMSIBinaryStream(string binaryId) { using (var sqlView = this.session.Database.OpenView("select Data from Binary where Name = '" + binaryId + "'")) { sqlView.Execute(); Stream data = sqlView.Fetch().GetStream(1); var retval = new MemoryStream(); int Length = 256; var buffer = new Byte[Length]; int bytesRead = data.Read(buffer, 0, Length); while (bytesRead > 0) { retval.Write(buffer, 0, bytesRead); bytesRead = data.Read(buffer, 0, Length); } return retval; } }
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:27,代码来源:WixCLRDialog.cs
在GetMSIBinaryStream()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例5 - SaveBNTXArray()
using System.IO; private static void SaveBNTXArray(Stream stream, List
Containers) { IsSavingArray = true; int Alignment = 4096; using (var saver = new FileWriter(stream, true)) { foreach (var container in Containers) { var mem = new System.IO.MemoryStream(); container.Save(mem); saver.Write(mem.ToArray()); saver.Align(Alignment); } } IsSavingArray = false; }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:20,代码来源:BNTX.cs
在SaveBNTXArray()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例6 - WriteMetaFooter()
using System.IO; ///
/// Writes a footer to a file for accessing meta data information outside a .pak archive. /// public static byte[] WriteMetaFooter(FileReader reader, uint metaOffset, string type, PACK pack) { //Magic + meta offset first var mem = new MemoryStream(); using (var writer = new FileWriter(mem)) { writer.SetByteOrder(!pack.IsLittleEndian); reader.SeekBegin(metaOffset); var file = GetFileForm(type); file.ReadMetaData(reader, pack.FileHeader); file.WriteMetaData(writer, pack.FileHeader); //Write footer header last writer.WriteSignature("META"); writer.WriteSignature(type); writer.Write(pack.FileHeader.VersionA); writer.Write(pack.FileHeader.VersionB); writer.Write((uint)(writer.BaseStream.Length + 4)); //size } return mem.ToArray(); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:27,代码来源:Common.cs
在WriteMetaFooter()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例7 - encodeETC()
public static byte[] encodeETC(Bitmap b) { int width = b.Width; int height = b.Height; int[] pixels = new int[width * height]; init(); int i, j; var mem = new System.IO.MemoryStream(); using (var writer = new FileWriter(mem)) { writer.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; for (i = 0; i < height; i += 8) { for (j = 0; j < width; j += 8) { int x, y; Color[] temp = new Color[16]; int pi = 0; for (x = i; x < i + 4; x++) for (y = j; y < j + 4; y++) temp[pi++] = b.GetPixel(y, x); writer.Write(GenETC1(temp)); temp = new Color[16]; pi = 0; for (x = i; x < i + 4; x++) for (y = j + 4; y < j + 8; y++) temp[pi++] = b.GetPixel(y, x); writer.Write(GenETC1(temp)); temp = new Color[16]; pi = 0; for (x = i + 4; x < i + 8; x++) for (y = j; y < j + 4; y++) temp[pi++] = b.GetPixel(y, x); writer.Write(GenETC1(temp)); temp = new Color[16]; pi = 0; for (x = i + 4; x < i + 8; x++) for (y = j + 4; y < j + 8; y++) temp[pi++] = b.GetPixel(y, x); writer.Write(GenETC1(temp)); } } } return mem.ToArray(); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:59,代码来源:ETC1_Encoder.cs
在encodeETC()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了4次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.Write的代码示例8 - InflateZLIB()
using System.IO; public static byte[] InflateZLIB(byte[] i) { var stream = new MemoryStream(); var ms = new MemoryStream(i); ms.ReadByte(); ms.ReadByte(); var zlibStream = new DeflateStream(ms, CompressionMode.Decompress); byte[] buffer = new byte[4095]; while (true) { int size = zlibStream.Read(buffer, 0, buffer.Length); if (size > 0) stream.Write(buffer, 0, buffer.Length); else break; } zlibStream.Close(); return stream.ToArray(); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:20,代码来源:FileReader.cs
在InflateZLIB()方法中,MemoryStream的代码示例类中的Write的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.Write方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。