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


C# BufferedStream.WriteNoAlloc方法代码示例

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


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

示例1: UpdateFileFormat

        private static void UpdateFileFormat(string originalVoxFile)
        {
            var newFile = Path.ChangeExtension(originalVoxFile, MyVoxelConstants.FILE_EXTENSION);
            if (!File.Exists(originalVoxFile))
            {
                MySandboxGame.Log.WriteLine(string.Format("ERROR: Voxel file '{0}' does not exists!", originalVoxFile));
            }
            if (Path.GetExtension(originalVoxFile) != "vox")
            {
                MySandboxGame.Log.WriteLine(string.Format("ERROR: Unexpected voxel file extensions in path: '{0}'", originalVoxFile));
            }

            using (var decompressFile = new MyCompressionFileLoad(originalVoxFile))
            using (var file = MyFileSystem.OpenWrite(newFile))
            using (var gzip = new GZipStream(file, CompressionMode.Compress))
            using (var buffer = new BufferedStream(gzip))
            {
                buffer.WriteNoAlloc(STORAGE_TYPE_NAME_CELL);

                // File version. New format will store it in 7bit encoded int right after the name of storage.
                buffer.Write7BitEncodedInt(decompressFile.GetInt32());

                // All remaining data is unchanged. Just copy it to new file.
                byte[] tmp = new byte[0x4000];
                int bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
                while (bytesRead != 0)
                {
                    buffer.Write(tmp, 0, bytesRead);
                    bytesRead = decompressFile.GetBytes(tmp.Length, tmp);
                }
            }
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:32,代码来源:MyStorageBase.cs

示例2: Save

        public void Save(out byte[] outCompressedData)
        {
            MyPrecalcComponent.AssertUpdateThread();

            ProfilerShort.Begin("MyStorageBase.Save");
            try
            {
                if (m_compressedData == null)
                {
                    MemoryStream ms;
                    using (ms = new MemoryStream(0x4000))
                    using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
                    using (BufferedStream buf = new BufferedStream(gz, 0x4000))
                    {
                        string name;
                        int version;
                        if (GetType() == typeof(MyOctreeStorage))
                        {
                            name = STORAGE_TYPE_NAME_OCTREE;
                            version = STORAGE_TYPE_VERSION_OCTREE;
                        }
                        else
                        {
                            throw new InvalidBranchException();
                        }
                        buf.WriteNoAlloc(name);
                        buf.Write7BitEncodedInt(version);
                        SaveInternal(buf);
                    }
                    m_compressedData = ms.ToArray();
                }

                outCompressedData = m_compressedData;
            }
            finally
            {
                ProfilerShort.End();
            }
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:39,代码来源:MyStorageBase.cs

示例3: SaveCompressedData

        protected void SaveCompressedData(out byte[] compressedData)
        {
            MemoryStream ms;
            using (ms = new MemoryStream(0x4000))
            using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
            using (BufferedStream buf = new BufferedStream(gz, 0x4000))
            {
                string name;
                int version;
                if (GetType() == typeof(MyOctreeStorage))
                {
                    name = STORAGE_TYPE_NAME_OCTREE;
                    version = STORAGE_TYPE_VERSION_OCTREE;
                }
                else
                {
                    throw new InvalidBranchException();
                }
                buf.WriteNoAlloc(name);
                buf.Write7BitEncodedInt(version);
                SaveInternal(buf);
            }

            compressedData = ms.ToArray();
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:25,代码来源:MyStorageBase.cs

示例4: Save

        public void Save(out byte[] outCompressedData)
        {
            Profiler.Begin("MyStorageBase.Save");
            try
            {
                if (m_compressedData == null)
                {
                    MemoryStream ms;
                    using (ms = new MemoryStream(0x4000))
                    using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
                    using (BufferedStream buf = new BufferedStream(gz, 0x4000))
                    {
                        var attr = m_attributesByType[GetType()];
                        buf.WriteNoAlloc(attr.SerializedTypeName);
                        buf.Write7BitEncodedInt(attr.SerializedVersion);
                        SaveInternal(buf);
                    }
                    m_compressedData = ms.ToArray();
                }

                outCompressedData = m_compressedData;
            }
            finally
            {
                Profiler.End();
            }
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:27,代码来源:MyStorageBase.cs


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