C# Stream.ReadByte的代码示例

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

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


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

Stream.ReadByte的代码示例1 - ReadLooseObjectHeader()

    using System.IO;

        private static bool ReadLooseObjectHeader(Stream input, out long size)
        {
            size = 0;

            byte[] buffer = new byte[5];
            input.Read(buffer, 0, buffer.Length);
            if (!Enumerable.SequenceEqual(buffer, LooseBlobHeader))
            {
                return false;
            }

            while (true)
            {
                int v = input.ReadByte();
                if (v == -1)
                {
                    return false;
                }

                if (v == '\0')
                {
                    break;
                }

                size = (size * 10) + (v - '0');
            }

            return true;
        }
    

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

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

Stream.ReadByte的代码示例2 - ReadReplaceLength()

    using System.IO;

        /// 
        /// Get the length of the replacement string.  For definition of data, see:
        /// https://github.com/git/git/blob/867b1c1bf68363bcfd17667d6d4b9031fa6a1300/Documentation/technical/index-format.txt#L38
        /// 
        /// stream to read bytes from
        /// 
        private int ReadReplaceLength(Stream stream)
        {
            int headerByte = stream.ReadByte();
            int offset = headerByte & 0x7f;

            // Terminate the loop when the high bit is no longer set.
            for (int i = 0; (headerByte & 0x80) != 0; i++)
            {
                headerByte = stream.ReadByte();
                if (headerByte < 0)
                {
                    throw new EndOfStreamException("Index file has been truncated.");
                }

                offset += 1;
                offset = (offset << 7) + (headerByte & 0x7f);
            }

            return offset;
        }
    

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

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

Stream.ReadByte的代码示例3 - Load()

    
        public void Load(System.IO.Stream stream)
        {
            using (FileReader reader = new FileReader(stream))
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;

                magic = reader.ReadBytes(4);

                uint magicval = magic[0] + 256 * (uint)(magic[1]) + 65536 * (uint)(magic[2]) + 16777216 * (uint)(magic[3]);

                if (magicval != MagicFileConstant)
                    throw new Exception("Invalid identifier");

                BlockDimX = reader.ReadByte();
                BlockDimY = reader.ReadByte();
                BlockDimZ = reader.ReadByte();
                xsize = reader.ReadBytes(3);
                ysize = reader.ReadBytes(3);
                zsize = reader.ReadBytes(3);

                Width = (uint)(xsize[0] + 256 * xsize[1] + 65536 * xsize[2]);
                Height = (uint)(ysize[0] + 256 * ysize[1] + 65536 * ysize[2]);
                Depth = (uint)(zsize[0] + 256 * zsize[1] + 65536 * zsize[2]);

                reader.Seek(0x10, System.IO.SeekOrigin.Begin);
                DataBlock = reader.ReadBytes((int)(reader.BaseStream.Length - reader.Position));

                Console.WriteLine(Width);
                Console.WriteLine(Height);
                Console.WriteLine(Depth);

                if (BlockDimX == 4 && BlockDimY == 4)
                    Format = TEX_FORMAT.ASTC_4x4_UNORM;
                else if (BlockDimX == 5 && BlockDimY == 4)
                    Format = TEX_FORMAT.ASTC_5x4_UNORM;
                else if (BlockDimX == 5 && BlockDimY == 5)
                    Format = TEX_FORMAT.ASTC_5x5_UNORM;
                else if (BlockDimX == 6 && BlockDimY == 5)
                    Format = TEX_FORMAT.ASTC_6x5_UNORM;
                else if (BlockDimX == 6 && BlockDimY == 6)
                    Format = TEX_FORMAT.ASTC_6x6_UNORM;
                else if (BlockDimX == 8 && BlockDimY == 5)
                    Format = TEX_FORMAT.ASTC_8x5_UNORM;
                else if (BlockDimX == 8 && BlockDimY == 6)
                    Format = TEX_FORMAT.ASTC_8x6_UNORM;
                else if (BlockDimX == 8 && BlockDimY == 8)
                    Format = TEX_FORMAT.ASTC_8x8_UNORM;
                else if (BlockDimX == 10 && BlockDimY == 10)
                    Format = TEX_FORMAT.ASTC_10x10_UNORM;
                else if (BlockDimX == 10 && BlockDimY == 5)
                    Format = TEX_FORMAT.ASTC_10x5_UNORM;
                else if (BlockDimX == 10 && BlockDimY == 6)
                    Format = TEX_FORMAT.ASTC_10x6_UNORM;
                else if (BlockDimX == 10 && BlockDimY == 8)
                    Format = TEX_FORMAT.ASTC_10x8_UNORM;
                else
                    throw new Exception($"Unsupported block dims! ({BlockDimX} x {BlockDimY})");
            }

            stream.Dispose();
            stream.Close();
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:63,代码来源:ASTC.cs

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

Stream.ReadByte的代码示例4 - Identify()

    using System.IO;

        public bool Identify(Stream stream, string fileName)
        {
            if (stream.Length < 16)
                return false;

            using (var reader = new FileReader(stream, true))
            {
                if(Utils.GetExtension(fileName) == ".lz")
                {
                    reader.SeekBegin(12);
                    return reader.ReadByte() == 0x11;
                }
            }
            return false;
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:17,代码来源:LZ77.cs

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

Stream.ReadByte的代码示例5 - Decompress()

    using System.IO;

        public Stream Decompress(Stream stream)
        {
            using (var reader = new FileReader(stream))
            {
                reader.SetByteOrder(false);

                var output = new System.IO.MemoryStream();
                if (reader.CheckSignature(4, "LZMA", 1))
                {
                    byte unk = reader.ReadByte(); //0xFF
                    uint magic = reader.ReadUInt32();
                    reader.ReadByte(); //padding
                    UseLZMAMagicHeader = true;
                }

                byte[] properties = reader.ReadBytes(5); //Property and dictionary size
                ulong decompressedSize = reader.ReadUInt64();

                var compressedSize = stream.Length - reader.Position;
                var copressedBytes = reader.ReadBytes((int)compressedSize);

                SevenZip.Compression.LZMA.Decoder decode = new SevenZip.Compression.LZMA.Decoder();
                decode.SetDecoderProperties(properties);

                MemoryStream ms = new MemoryStream(copressedBytes);
                decode.Code(ms, output, compressedSize, (int)decompressedSize, null);

                return output;
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:32,代码来源:LZMA.cs

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

Stream.ReadByte的代码示例6 - Load()

            public void Load(System.IO.Stream stream)
        {
            CanSave = true;

            using (var reader = new FileReader(stream))
            {
                if (IsSA01)
                    reader.SetByteOrder(true);
                else
                    reader.SetByteOrder(false);

                uint Signature = reader.ReadUInt32();
                uint FileCount = reader.ReadUInt32();
                Alignment = reader.ReadUInt32();
                uint[] DataOffsets = reader.ReadUInt32s((int)FileCount);
                uint[] Sizes = reader.ReadUInt32s((int)FileCount);

                string[] FileNames = new string[FileCount];
                for (int i = 0; i < FileCount; i++)
                {
                    FileNames[i] = reader.ReadZeroTerminatedString();
                    while (true)
                    {
                        if (reader.ReadByte() != 0x30)
                        {
                            reader.Seek(-1);
                            break;
                        }
                    }
                }

                long DataPosition = reader.Position;
                for (int i = 0; i < FileCount; i++)
                {
                   //reader.SeekBegin(DataPosition + DataOffsets[i]);
                    var file = new FileEntry();
                    file.FileName = FileNames[i];
                    file.FileData = reader.ReadBytes((int)Sizes[i]);
                    files.Add(file);

                    while (true)
                    {
                        if (reader.EndOfStream)
                            break;

                        if (reader.ReadByte() != 0x30)
                        {
                            reader.Seek(-1);
                            break;
                        }
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:54,代码来源:ME01.cs

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

Stream.ReadByte的代码示例7 - GetExternalFlags()

    using System.IO;

        public static ExternalFlags GetExternalFlags(Stream stream)
        {
            using (var reader = new FileReader(stream, true))
            {
                using (reader.TemporarySeek(10, SeekOrigin.Begin))
                {
                    byte version = reader.ReadByte();
                    //Check if bfres supports external strings or not
                    if (version < 10)
                        return (ExternalFlags)0;

                    //Check external flags
                    reader.SeekBegin(0xee);
                    ExternalFlags flag = (ExternalFlags)reader.ReadByte();
                    byte flag2 = reader.ReadByte(); 
                    if (flag2 == 1) //flag custom set by bfres resave to detect an mc resave
                        return ExternalFlags.MeshCodecResave;
                    return flag;
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:23,代码来源:MeshCodec.cs

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

Stream.ReadByte的代码示例8 - Load()

    using System.IO;

        public void Load(Stream stream) {
            using(FileReader reader = new FileReader(stream)) {
                //DirectoryEntry currentDirEntry = rootDir;
                string currentDir = string.Empty;

                header = new Header(reader);

                reader.ReadSignature(4, "BTAF");

                // The positions where the sections' reading was left last time.
                long bfatIndex = reader.Position + 8;
                long bfntIndex = reader.Position + reader.ReadUInt32(); // From the BFAT length.
                long fimgIndex;

                uint fileCount = reader.ReadUInt32();

                uint currentFileOffset;
                uint currentFileEnd;

                reader.Position = bfntIndex;

                fimgIndex = reader.Position + reader.ReadUInt32() + 4; // Sets FIMG section begining.
                bfntUnk = reader.ReadBytes(reader.ReadInt32() - 4);

                for(int i = 0; i < fileCount; i++) {
                    byte nameLength = reader.ReadByte();

                    if(nameLength == 0x00) { // End of the "folder".
                        List slashIndices = new List();
                        for(int j = 0; j < currentDir.Length; j++)
                            if(currentDir[j] == '/')
                                slashIndices.Add(j);

                        int lastSlash = slashIndices.Last();
                        slashIndices.Remove(lastSlash);
                        int slashBeforeLast = slashIndices.Count > 0 ? slashIndices.Last() : 0;

                        currentDir = currentDir.Remove(slashBeforeLast + 1);

                        if(currentDir.Length == 1)
                            currentDir = string.Empty;

                        i--;
                        continue;
                    }

                    if(nameLength >= 0x80) { // If it is a "folder".
                        // Disable file modifications:
                        CanSave = false;
                        CanAddFiles = false;
                        CanRenameFiles = false;
                        CanReplaceFiles = false;
                        CanDeleteFiles = false;

                        string dirName = reader.ReadString(nameLength & 0x7F);
                        currentDir += dirName + "/";

                        reader.Position += 2;
                        i--;
                        continue;
                    }

                    // Read BFAT section:
                    using(reader.TemporarySeek()) {
                        reader.Position = bfatIndex;

                        currentFileOffset = reader.ReadUInt32();
                        currentFileEnd = reader.ReadUInt32();

                        bfatIndex = reader.Position;
                    }

                    string name = reader.ReadString(nameLength);

                    using(reader.TemporarySeek()) {
                        reader.Position = fimgIndex + currentFileOffset;
                        files.Add(new FileEntry(this) {
                            FileName = currentDir + name,
                            BlockData = reader.ReadBytes((int) (currentFileEnd - currentFileOffset))
                    });
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:86,代码来源:NARC.cs

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

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