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


C# MemoryStream.ReadAllBytes方法代码示例

本文整理汇总了C#中System.IO.MemoryStream.ReadAllBytes方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ReadAllBytes方法的具体用法?C# MemoryStream.ReadAllBytes怎么用?C# MemoryStream.ReadAllBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.MemoryStream的用法示例。


在下文中一共展示了MemoryStream.ReadAllBytes方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestReadAllBytes

        public void TestReadAllBytes()
        {
            var fromBytes = Enumerable.Repeat<byte>(1, 1024 * 1024)
                .Concat(Enumerable.Repeat<byte>(2, 1024 * 1024))
                .Concat(Enumerable.Repeat<byte>(3, 1024 * 1024)).ToArray();

            var stream = new MemoryStream(fromBytes);

            var toBytes = stream.ReadAllBytes();

            Assert.IsTrue(fromBytes.SequenceEqual(toBytes));
        }
开发者ID:tommyinb,项目名称:TommiUtility,代码行数:12,代码来源:StreamUtil.cs

示例2: Enqueue

        public void Enqueue(EnvelopeToken envelope)
        {
            using (var stream = new MemoryStream())
            {
                _formatter.Serialize(stream, envelope);

                stream.Position = 0;
                var bytes = stream.ReadAllBytes();

                _queue.Add(bytes);
            }
        }
开发者ID:kingreatwill,项目名称:fubumvc,代码行数:12,代码来源:InMemoryQueue.cs

示例3: read_all_bytes

        public void read_all_bytes()
        {
            var helloWorld = "Hello world.";
            var bytes = Encoding.Unicode.GetBytes(helloWorld);

            var stream = new MemoryStream();
            stream.Write(bytes, 0, bytes.Length);

            stream.Position = 0;

            var actual = stream.ReadAllBytes();

            actual.ShouldBe(bytes);
        }
开发者ID:JasperFx,项目名称:baseline,代码行数:14,代码来源:StreamExtensionsTests.cs

示例4: Extract_PackageContainsFiles_ContentOfEachFileIsWrittenToDisc

        public void Extract_PackageContainsFiles_ContentOfEachFileIsWrittenToDisc()
        {
            // Arrange
            string targetFolder = Environment.CurrentDirectory;

            string file1Path = "tools\\file1.txt";
            string file1Content = Guid.NewGuid().ToString();
            Stream file1Stream = TestUtilities.GetStreamReaderForText(file1Content).BaseStream;
            var file1 = new Mock<IPackageFile>();
            file1.Setup(f => f.Path).Returns(file1Path);
            file1.Setup(f => f.GetStream()).Returns(file1Stream);

            var files = new List<IPackageFile> { file1.Object };

            string packageId = "Package.A";
            var version = new SemanticVersion(1, 0, 0, 0);
            var packageDirectory = Path.Combine(targetFolder, string.Format("{0}.{1}", packageId, version));

            var package = new Mock<IPackage>();
            package.Setup(p => p.Id).Returns(packageId);
            package.Setup(p => p.Version).Returns(version);
            package.Setup(p => p.GetFiles()).Returns(files);

            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            filesystemAccessor.Setup(f => f.DirectoryExists(packageDirectory)).Returns(true);
            filesystemAccessor.Setup(f => f.DeleteDirectory(packageDirectory)).Returns(true);

            var writeStream = new MemoryStream();
            var streamWriter = new StreamWriter(writeStream);
            filesystemAccessor.Setup(f => f.GetWriteStream(It.Is<string>(s => s.EndsWith(file1Path)))).Returns(streamWriter.BaseStream);

            var nugetPackageExtractor = new NugetPackageExtractor(filesystemAccessor.Object);

            // Act
            var result = nugetPackageExtractor.Extract(package.Object, targetFolder);

            // Assert
            var bytes = writeStream.ReadAllBytes();
            string newContentOfOldFile = Encoding.UTF8.GetString(bytes);

            Assert.IsNotNull(result);
            Assert.AreEqual(file1Content, newContentOfOldFile);

            file1.Verify(f => f.GetStream(), Times.Once());
            filesystemAccessor.Verify(f => f.GetWriteStream(It.Is<string>(s => s.StartsWith(packageDirectory))), Times.Once());
        }
开发者ID:andreaskoch,项目名称:NuDeploy,代码行数:47,代码来源:NugetPackageExtractorTests.cs

示例5: Serialize

        public void Serialize(Envelope envelope)
        {
            if (envelope.Message == null) throw new InvalidOperationException("No message on this envelope to serialize");

            if (envelope.ContentType.IsEmpty())
            {
                envelope.ContentType = _graph.DefaultContentType;
            }

            var serializer = selectSerializer(envelope);
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(envelope.Message, stream);
                stream.Position = 0;

                envelope.Data = stream.ReadAllBytes();
            }
        }
开发者ID:JackGilliam1,项目名称:FubuTransportation,代码行数:18,代码来源:EnvelopeSerializer.cs

示例6: StreamTest

 public void StreamTest()
 {
     MemoryStream stream = new MemoryStream();
     stream.WriteAllBytes(CommonHelper.StringToByte("Hello"));
     stream.Position = 0;
     var bytes = stream.ReadAllBytes();
     Assert.AreEqual(CommonHelper.ByteToString(bytes), "Hello");
 }
开发者ID:hoangvv1409,项目名称:codebase,代码行数:8,代码来源:CommonLibTest.cs

示例7: Encode

            public static object Encode(SQLInfo.ColDef col, object data)
            {
                if (data == null) return null;

                //Logger.ReportVerbose("Encoding " + col.ColName + " as " + col.ColType.Name.ToLower());
                switch (col.ColType.Name.ToLower())
                {
                    case "guid":
                        return data.ToString();
                    case "string":
                        return data;

                    case "datetime":
                        return ((DateTime)data).Ticks;

                    case "mediatype":
                        return ((MediaType)data).ToString();

                    case "videoformat":
                        return ((VideoFormat)data).ToString();

                    case "downloadpolicy":
                        return ((MediaBrowser.Library.Network.DownloadPolicy)data).ToString();

                    case "int":
                    case "int16":
                    case "int32":
                    case "int64":
                    case "long":
                    case "double":
                    case "nullable`1":
                        return data;
                    default:
                        var ms = new MemoryStream();
                        Serializer.Serialize<object>(ms,data);
                        ms.Seek(0,0);
                        return ms.ReadAllBytes();

                }
            }
开发者ID:rickbassham,项目名称:videobrowser,代码行数:40,代码来源:SqliteItemRepository.cs

示例8: PublishPackage

        private void PublishPackage(PublishState state)
        {
            var url = new Uri(String.Format(CultureInfo.InvariantCulture, "{0}/{1}", _baseGalleryServerUrl, PublishPackageService));

            using (Stream requestStream = new MemoryStream()) {
                var data = new PublishData {
                    Key = state.PublishKey,
                    Id = state.PackageMetadata.Id,
                    Version = state.PackageMetadata.Version.ToString()
                };

                var jsonSerializer = new DataContractJsonSerializer(typeof(PublishData));
                jsonSerializer.WriteObject(requestStream, data);
                requestStream.Seek(0, SeekOrigin.Begin);

                WebClient client = new WebClient();
                client.Proxy = _cachedProxy;
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                client.Headers[HttpRequestHeader.UserAgent] = _userAgent;
                client.UploadProgressChanged += OnUploadProgressChanged;
                client.UploadDataCompleted += OnPublishPackageCompleted;
                client.UploadDataAsync(url, "POST", requestStream.ReadAllBytes(), state);
            }
        }
开发者ID:jacksonh,项目名称:nuget,代码行数:24,代码来源:GalleryServer.cs

示例9: Version

        public void SelfUpdate_PackageIsFound_VersionIsNewerThanTheCurrentVersion_PackageContainsExeWhichNameMatchesTheApplication_PackageContentIsWrittenToExecutable()
        {
            // Arrange
            string exePath = "NuDeploy.exe";
            var version = new Version(1, 0, 0, 0);

            var userInterface = new Mock<IUserInterface>();
            var applicationInformation = new ApplicationInformation { NameOfExecutable = exePath };
            var packageRepositoryBrowser = new Mock<IPackageRepositoryBrowser>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();

            var packageContent = "Content of the update package";
            var packageContentStream = TestUtilities.GetStreamReaderForText(packageContent).BaseStream;

            var packageFileMock = new Mock<IPackageFile>();
            packageFileMock.Setup(f => f.Path).Returns("tools\\" + exePath);
            packageFileMock.Setup(f => f.GetStream()).Returns(packageContentStream);

            var packageMock = new Mock<IPackage>();
            packageMock.Setup(p => p.Version).Returns(new SemanticVersion(2, 0, 0, 0));
            packageMock.Setup(p => p.GetFiles()).Returns(new List<IPackageFile> { packageFileMock.Object });

            var targetStream = new MemoryStream();
            filesystemAccessor.Setup(f => f.GetWriteStream(exePath)).Returns(targetStream);

            packageRepositoryBrowser.Setup(p => p.FindPackage(It.IsAny<string>())).Returns(packageMock.Object);

            var selfUpdateService = new SelfUpdateService(
                userInterface.Object, applicationInformation, packageRepositoryBrowser.Object, filesystemAccessor.Object);

            // Act
            bool result = selfUpdateService.SelfUpdate(exePath, version);

            // Assert
            var bytes = targetStream.ReadAllBytes();
            string newContentOfOldFile = Encoding.UTF8.GetString(bytes);
            filesystemAccessor.Verify(f => f.GetWriteStream(exePath), Times.Once());
            Assert.AreEqual(packageContent, newContentOfOldFile);
            Assert.IsTrue(result);
        }
开发者ID:andreaskoch,项目名称:NuDeploy,代码行数:40,代码来源:SelfUpdateServiceTests.cs

示例10: ExtractAssembly

 private Assembly ExtractAssembly(ZipEntry entry)
 {
     var stream = new MemoryStream();
     entry.Extract(stream);
     return Assembly.Load(stream.ReadAllBytes());
 }
开发者ID:chartly,项目名称:flood,代码行数:6,代码来源:PackageLoader.cs

示例11: Should_Read_To_Array

        public void Should_Read_To_Array()
        {
            var bytes = new byte[] { 1, 2, 3 };
            var stream = new MemoryStream(bytes);

            Assert.AreEqual(bytes, stream.ReadAllBytes());
        }
开发者ID:justin-arvay,项目名称:WebAssetBundler,代码行数:7,代码来源:StreamExtensionsTests.cs

示例12: Serialize

        public byte[] Serialize()
        {
            using (var stream = new MemoryStream())
            {
                new BinarySerializer().Serialize(this, stream);
                stream.Position = 0;
                return stream.ReadAllBytes();
            }

            
        }
开发者ID:kingreatwill,项目名称:fubumvc,代码行数:11,代码来源:ErrorReport.cs


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