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


C# FileStream.WriteInt方法代码示例

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


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

示例1: writeMetadataTableInfo

 private static void writeMetadataTableInfo(FileStream metadataStream, MetadataTableInfo info, int offset)
 {
     metadataStream.WriteASCII(info.identifier, offset);
     metadataStream.WriteInt(info.tableOffset.value, offset + IDENTIFIER_LENGTH);
     metadataStream.WriteInt(info.numEntries, offset + 4 + IDENTIFIER_LENGTH);
     metadataStream.WriteInt(info.totalLength, offset + 8 + IDENTIFIER_LENGTH);
 }
开发者ID:Crazycolorz5,项目名称:FEEditorSuite2015ProDeluxeEdition,代码行数:7,代码来源:MetadataManager.cs

示例2: writeMetadata

        public void writeMetadata()
        {
            //metadataStream.Seek(0, SeekOrigin.Begin);

            //TODO
            //Load all tables into RAM, erase the file, rewrite all the tables.
            mainTable.info.numEntries = tables.Count;

            metadataStream = File.Open(metadataPath, FileMode.Open);

            MetadataTableInfo[] tableInfo = new MetadataTableInfo[tables.Count];
            var myData = new List<Metadata>();
            foreach(var table in tables)
            {
                myData.Add(table.Value);
            }

            for(int i=0; i<tables.Count; i++)
            {
                tableInfo[i] = myData[i].info;
            }
            int [] tableInfoOffsets = new int[myData.Count];

            int offs_acc = TABLE_INFO_SIZE;

            for(int i=0; i<myData.Count; i++)
            {
                tableInfoOffsets[i] = offs_acc;
                MetadataTableInfo curTable;
                curTable = myData[i].info;
                offs_acc += TABLE_INFO_SIZE;
            }

            mainTable.info.tableOffset = new Pointer(offs_acc); //start of main data
            //mainTable.data = new List<Tuple<int, byte[]>>();

            //now write the main table
            for (int i = 0; i < myData.Count; i++)
            {
                metadataStream.WriteInt(4, offs_acc);
                offs_acc += 4;
                metadataStream.WriteInt(tableInfoOffsets[i], offs_acc);
                offs_acc += 4;
                //mainTable.data.Add(Tuple.Create(4, BitConverter.GetBytes(tableInfoOffsets[i])));
            }

            //now write all the other tables' data
            for (int i=0; i<myData.Count; i++)
            {
                tableInfo[i].tableOffset = new Pointer(offs_acc);
                for(int j=0; j<myData[i].data.Count; j++)
                {
                    int len = myData[i].data[j].Item1;
                    metadataStream.WriteInt(len, offs_acc); //length
                    offs_acc += 4;
                    metadataStream.Seek(offs_acc, SeekOrigin.Begin);
                    metadataStream.Write(myData[i].data[j].Item2, 0, len);
                    offs_acc += len;
                    int align_diff = HexTools.align(offs_acc) - offs_acc;
                    if(align_diff!=0)
                    {
                        byte[] alignment = new byte[align_diff];
                        Array.Clear(alignment, 0, align_diff);
                        metadataStream.Write(alignment, 0, align_diff);
                    }
                    offs_acc += align_diff;
                }
            }
            metadataStream.SetLength(offs_acc);

            //now go back to the top and write all the table data
            writeMetadataTableInfo(metadataStream, mainTable.info, 0);
            offs_acc = TABLE_INFO_SIZE;

            for (int i = 0; i < myData.Count; i++)
            {
                writeMetadataTableInfo(metadataStream, tableInfo[i], offs_acc);
                offs_acc += TABLE_INFO_SIZE;
            }

            mainTable = readMetadataTable(metadataStream, 0);

            metadataStream.Flush();
            metadataStream.Close();

            //And we're done.

            //All headers, then all data
            //TableData1, TableData2, TableData3, . . .
            //length, dataaaaaaaaaaaa; length, dataaaaaaaaaaaaa, . . .
        }
开发者ID:Crazycolorz5,项目名称:FEEditorSuite2015ProDeluxeEdition,代码行数:91,代码来源:MetadataManager.cs


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