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


C# FileStream.ReadString方法代码示例

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


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

示例1: FromFile

        public static Game FromFile(string filepath)
        {
            using (FileStream fs = new FileStream(filepath, FileMode.Open))
            {
                string hash = fs.ReadString();
                string owner = fs.ReadString();
                string repo = fs.ReadString();
                string token = fs.ReadString();
                byte set = (byte)fs.ReadInt32();

                Game game = new Game(filepath, token, owner, repo, hash);

                game.users = new User[fs.ReadInt32()];
                for (int i = 0; i < game.users.Length; i++)
                    game.users[i] = User.FromStream(fs);

                game.contributors = new string[fs.ReadInt32()];
                for (int i = 0; i < game.contributors.Length; i++)
                    game.contributors[i] = fs.ReadString();

                game.rowCount = fs.ReadInt32();
                game.commits = new CommitCollection(game);

                game.tableStart = fs.Position;
                game.rowSize = 40 + game.users.Length;

                for (game.tableIndex = 0; game.tableIndex < game.rowCount; game.tableIndex++)
                {
                    fs.Seek(40, SeekOrigin.Current);
                    bool stop = false;

                    for (int i = 0; i < game.users.Length; i++)
                        if (fs.ReadByte() == 0)
                        {
                            stop = true;
                            fs.Seek(-(40 + i + 1), SeekOrigin.Current);
                            break;
                        }

                    if (stop)
                        break;
                }

                fs.Seek(game.tableStart + game.rowCount * game.rowSize, SeekOrigin.Begin);
                while (fs.Position < fs.Length)
                    game.messages.Add(Message.FromStream(fs));

                return game;
            }
        }
开发者ID:SickTeam,项目名称:GitGameServer,代码行数:50,代码来源:Game.cs

示例2: ReplayMetadata

        ReplayMetadata(FileStream fs, string path)
        {
            FilePath = path;

            // Read start marker
            if (fs.ReadInt32() != MetaStartMarker)
                throw new InvalidOperationException("Expected MetaStartMarker but found an invalid value.");

            // Read version
            var version = fs.ReadInt32();
            if (version != MetaVersion)
                throw new NotSupportedException("Metadata version {0} is not supported".F(version));

            // Read game info (max 100K limit as a safeguard against corrupted files)
            var data = fs.ReadString(Encoding.UTF8, 1024 * 100);
            GameInfo = GameInformation.Deserialize(data);
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:17,代码来源:ReplayMetadata.cs

示例3: CompressCss

 private string CompressCss(IEnumerable<IPath> cssFiles)
 {
     StringBuilder sb = new StringBuilder();
     foreach (var file in cssFiles)
     {
         using (FileStream fileStream = new FileStream(file.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             var content = fileStream.ReadString();
             sb.AppendFormat("{0}\n", CSSMinify.Minify(Url, file.VirtualPath, Request.Url.AbsolutePath, content));
         }
     }
     return sb.ToString();
 }
开发者ID:Epitomy,项目名称:CMS,代码行数:13,代码来源:ResourceController.cs

示例4: Read

 public string Read()
 {
     if (this.Exists())
     {
         using (FileStream fs = new FileStream(this.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             this.body = fs.ReadString();
         }
     }
     return this.body;
 }
开发者ID:jason1234,项目名称:CMS,代码行数:11,代码来源:FileResource.cs

示例5: ReadAsString

 public static string ReadAsString(string filePath)
 {
     using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
     {
         return fileStream.ReadString();
     }
 }
开发者ID:Epitomy,项目名称:CMS,代码行数:7,代码来源:IOUtility.cs

示例6: CreateHeader

        public override MemoryStream CreateHeader(string[] files, string[] archiveFilenames, int blockSize, bool[] settings, out uint[] offsetList)
        {
            try
            {
                /* Let's get out settings now */
                blockSize = 24;
                bool addFilename    = settings[0];
                bool addPixelFormat = settings[1];
                bool addDimensions  = settings[2];
                bool addGlobalIndex = settings[3];

                /* Let's figure out the metadata size, so we can create the header properly */
                int metaDataSize = 2;
                if (addFilename)    metaDataSize += 28;
                if (addPixelFormat) metaDataSize += 2;
                if (addDimensions)  metaDataSize += 2;
                if (addGlobalIndex) metaDataSize += 4;

                /* Create the header now */
                offsetList          = new uint[files.Length];
                MemoryStream header = new MemoryStream(Number.RoundUp(0xC + (files.Length * metaDataSize), blockSize));
                header.Write(ArchiveHeader.GVM, 4);
                header.Write(header.Capacity);

                /* Set up format type */
                byte formatType = 0x0;
                if (addFilename)    formatType |= (1 << 3);
                if (addPixelFormat) formatType |= (1 << 2);
                if (addDimensions)  formatType |= (1 << 1);
                if (addGlobalIndex) formatType |= (1 << 0);
                header.WriteByte(0x0);
                header.WriteByte(formatType);

                /* Write number of files */
                header.Write(((ushort)files.Length).SwapEndian());

                uint offset = (uint)header.Capacity + 8;

                /* Start writing the information in the header */
                for (int i = 0; i < files.Length; i++)
                {
                    using (FileStream data = new FileStream(files[i], FileMode.Open, FileAccess.Read))
                    {
                        /* Make sure this is a GVR */
                        Images images = new Images(data, files[i]);
                        if (images.Format != GraphicFormat.GVR)
                            throw new IncorrectGraphicFormat();

                        /* Get the header offset */
                        int headerOffset = (data.ReadString(0x0, 4) == GraphicHeader.GVRT ? 0x0 : 0x10);

                        offsetList[i] = offset;
                        header.Write(((ushort)i).SwapEndian());

                        if (addFilename)
                            header.Write(Path.GetFileNameWithoutExtension(archiveFilenames[i]), 27, 28);
                        if (addPixelFormat)
                            header.Write(data, headerOffset + 0xA, 2);
                        if (addDimensions)
                        {
                            /* Get the width and height */
                            int width  = (int)Math.Min(Math.Log(data.ReadUShort(headerOffset + 0xC).SwapEndian(), 2) - 2, 9);
                            int height = (int)Math.Min(Math.Log(data.ReadUShort(headerOffset + 0xE).SwapEndian(), 2) - 2, 9);
                            header.WriteByte(0x0);
                            header.WriteByte((byte)((width << 4) | height));
                        }
                        if (addGlobalIndex)
                        {
                            if (headerOffset == 0x0)
                                header.Write(new byte[] {0x0, 0x0, 0x0, 0x0});
                            else
                                header.Write(data, 0x8, 4);
                        }

                        offset += Number.RoundUp((uint)(data.Length - headerOffset), blockSize);
                    }
                }

                return header;
            }
            catch (IncorrectGraphicFormat)
            {
                offsetList = null;
                return null;
            }
            catch
            {
                offsetList = null;
                return null;
            }
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:91,代码来源:gvm.cs

示例7: ParseHeader

        /// <summary>
        /// Read in and validate the header of a city file.
        /// </summary>
        /// <param name="stream">File stream waiting at the header for instructions.</param>
        /// <returns>The length (in bytes) of the data portion of this file.</returns>
        private static int ParseHeader(FileStream reader)
        {
            // Case for too small of a file
            if (reader.Length < 12)
                throw new Exception("Unexpected file length.");

            // Read 12-byte header.
            string headChunk = reader.ReadString();
            int dataLength = reader.Read4ByteInt();
            string fileType = reader.ReadString();

            // Make sure the header represents a valid city file.
            if (!headChunk.Equals(HEADERCHUNK) || !fileType.Equals(FILETYPE))
                throw new Exception("Invalid SC2000 file or corrupted header.");

            return dataLength;
        }
开发者ID:tgp1994,项目名称:city-parser-2000,代码行数:22,代码来源:CityParser.cs


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