C# FileStream.ReadByte的代码示例

通过代码示例来学习C# FileStream.ReadByte方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


FileStream.ReadByte是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的FileStream.ReadByte() 已经帮大家高亮显示了,大家可以重点学习FileStream.ReadByte() 方法的写法,从而快速掌握该方法的应用。

FileStream.ReadByte的代码示例1 - ReadingFileDoesNotUpdateIndexOrModifiedPaths()

    using System.IO;

        [TestCase, Order(7)]
        public void ReadingFileDoesNotUpdateIndexOrModifiedPaths()
        {
            string gitFileToCheck = "GVFS/GVFS.FunctionalTests/Category/CategoryConstants.cs";
            string virtualFile = this.Enlistment.GetVirtualPathTo(gitFileToCheck);
            ProcessResult initialResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "ls-files --debug -svmodc " + gitFileToCheck);
            initialResult.ShouldNotBeNull();
            initialResult.Output.ShouldNotBeNull();
            initialResult.Output.StartsWith("S ").ShouldEqual(true);
            initialResult.Output.ShouldContain("ctime: 0:0", "mtime: 0:0", "size: 0\t");

            using (FileStream fileStreamToRead = File.OpenRead(virtualFile))
            {
                fileStreamToRead.ReadByte();
            }

            this.Enlistment.WaitForBackgroundOperations();

            ProcessResult afterUpdateResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "ls-files --debug -svmodc " + gitFileToCheck);
            afterUpdateResult.ShouldNotBeNull();
            afterUpdateResult.Output.ShouldNotBeNull();
            afterUpdateResult.Output.StartsWith("S ").ShouldEqual(true);
            afterUpdateResult.Output.ShouldContain("ctime: 0:0", "mtime: 0:0", "size: 0\t");

            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, this.fileSystem, gitFileToCheck);
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:28,代码来源:GitFilesTests.cs

在ReadingFileDoesNotUpdateIndexOrModifiedPaths()方法中,FileStream的代码示例类中的ReadByte的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

FileStream.ReadByte的代码示例2 - TruncatedObjectRedownloaded()

    using System.IO;

        [TestCase, Order(17)]
        public void TruncatedObjectRedownloaded()
        {
            GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "checkout " + this.Enlistment.Commitish);
            ProcessResult revParseResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "rev-parse :Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded.txt");
            string sha = revParseResult.Output.Trim();
            sha.Length.ShouldEqual(40);
            string objectPath = Path.Combine(this.Enlistment.GetObjectRoot(this.fileSystem), sha.Substring(0, 2), sha.Substring(2, 38));
            objectPath.ShouldNotExistOnDisk(this.fileSystem);

            string corruptObjectFolderPath = Path.Combine(this.Enlistment.DotGVFSRoot, "CorruptObjects");
            int initialCorruptObjectCount = 0;
            if (this.fileSystem.DirectoryExists(corruptObjectFolderPath))
            {
                initialCorruptObjectCount = new DirectoryInfo(corruptObjectFolderPath).EnumerateFileSystemInfos().Count();
            }

            // Read a copy of TruncatedObjectRedownloaded.txt to force the object to be downloaded
            GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "rev-parse :Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded_copy.txt").Output.Trim().ShouldEqual(sha);
            string testFileContents = this.Enlistment.GetVirtualPathTo("Test_EPF_WorkingDirectoryTests", "TruncatedObjectRedownloaded_copy.txt").ShouldBeAFile(this.fileSystem).WithContents();
            objectPath.ShouldBeAFile(this.fileSystem);
            string modifedFile = "Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded.txt";
            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, this.fileSystem, modifedFile);

            // Truncate the contents of objectPath
            string tempTruncatedObjectPath = objectPath + "truncated";
            FileInfo objectFileInfo = new FileInfo(objectPath);
            long objectLength = objectFileInfo.Length;
            using (FileStream objectStream = new FileStream(objectPath, FileMode.Open))
            using (FileStream truncatedObjectStream = new FileStream(tempTruncatedObjectPath, FileMode.CreateNew))
            {
                for (int i = 0; i < (objectStream.Length - 16); ++i)
                {
                    truncatedObjectStream.WriteByte((byte)objectStream.ReadByte());
                }
            }

            this.fileSystem.DeleteFile(objectPath);
            this.fileSystem.MoveFile(tempTruncatedObjectPath, objectPath);
            tempTruncatedObjectPath.ShouldNotExistOnDisk(this.fileSystem);
            objectPath.ShouldBeAFile(this.fileSystem);
            new FileInfo(objectPath).Length.ShouldEqual(objectLength - 16);

            // Windows should correct a corrupt obect
            // Read the original path and verify its contents are correct
            this.Enlistment.GetVirtualPathTo("Test_EPF_WorkingDirectoryTests", "TruncatedObjectRedownloaded.txt").ShouldBeAFile(this.fileSystem).WithContents(testFileContents);

            // Confirm there's a new item in the corrupt objects folder
            corruptObjectFolderPath.ShouldBeADirectory(this.fileSystem).WithItems().Count().ShouldEqual(initialCorruptObjectCount + 1);

            // File should not be in ModifiedPaths.dat
            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, this.fileSystem, "Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded.txt");
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:55,代码来源:WorkingDirectoryTests.cs

在TruncatedObjectRedownloaded()方法中,FileStream的代码示例类中的ReadByte的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

FileStream.ReadByte的代码示例3 - CreateFileAppender()

    using System.IO;
        /// 
        /// open a stream with optional trim extra blank lines
        /// 
        /// Filename to open
        /// encoding of the file
        /// do we trim blank lines from end?
        /// do we close stream after trimming
        /// Buffer size to read
        /// TextWriter ready to write to
        internal static TextWriter CreateFileAppender(string fileName,
            Encoding encode,
            bool correctEnd,
            bool disposeStream,
            int bufferSize)
        {
            TextWriter res;

            if (correctEnd) {
                FileStream fs = null;

                try {
                    fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

                    //bool CarriageReturn = false;
                    //bool LineFeed = false;

                    // read the file backwards using SeekOrigin.Begin...
                    long offset;
                    for (offset = fs.Length - 1; offset >= 0; offset--) {
                        fs.Seek(offset, SeekOrigin.Begin);
                        int value = fs.ReadByte();
                        if (value == '\r') {
                        }
                        else if (value == '\n') {
                        }
                        else
                            break;
                    }
                    if (offset >= 0) // read something else other than line ends...
                    {
                        var newLine = Environment.NewLine;
                        var newline = new byte[newLine.Length];
                        int count = 0;
                        foreach (var ch in newLine) {
                            newline[count] = Convert.ToByte(ch);
                            count++;
                        }
                        // Console.WriteLine(" value {0} count {1}\n", newline.Length, count);

                        fs.Write(newline, 0, count);
                    }
                    res = new StreamWriter(fs, encode, bufferSize);
                }
                finally {
                    if (disposeStream && fs != null)
                        fs.Close();
                }
            }
            else
                res = new StreamWriter(fileName, true, encode, bufferSize);
            return res;
        }
    

开发者ID:MarcosMeli,项目名称:FileHelpers,代码行数:63,代码来源:StreamHelper.cs

在CreateFileAppender()方法中,FileStream的代码示例类中的ReadByte的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

FileStream.ReadByte的代码示例4 - QuickVerifyJsonFile()

    using System.IO;

        public static bool QuickVerifyJsonFile(string filePath)
        {
            try
            {
                if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
                {
                    using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        if (fileStream.Length > 1 && fileStream.ReadByte() == (byte)'{')
                        {
                            fileStream.Seek(-1, SeekOrigin.End);
                            return fileStream.ReadByte() == (byte)'}';
                        }
                    }
                }
            }
            catch
            {
            }

            return false;
        }
    

开发者ID:ShareX,项目名称:ShareX,代码行数:24,代码来源:JsonHelpers.cs

在QuickVerifyJsonFile()方法中,FileStream的代码示例类中的ReadByte的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

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