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


C# Stream.ReadBytes方法代码示例

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


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

示例1: ParseFrames

        TmpTDFrame[] ParseFrames(Stream s)
        {
            var start = s.Position;
            var width = s.ReadUInt16();
            var height = s.ReadUInt16();
            var size = new Size(width, height);

            s.Position += 8;
            var imgStart = s.ReadUInt32();
            s.Position += 8;
            var indexEnd = s.ReadInt32();
            var indexStart = s.ReadInt32();

            s.Position = indexStart;
            var count = indexEnd - indexStart;
            var tiles = new TmpTDFrame[count];
            var tilesIndex = 0;
            foreach (var b in s.ReadBytes(count))
            {
                if (b != 255)
                {
                    s.Position = imgStart + b * width * height;
                    tiles[tilesIndex++] = new TmpTDFrame(s.ReadBytes(width * height), size);
                }
                else
                    tiles[tilesIndex++] = new TmpTDFrame(null, size);
            }

            s.Position = start;
            return tiles;
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:31,代码来源:TmpTDLoader.cs

示例2: ReadBlock

 public static void ReadBlock(Stream stream, out BlockType blockType, out byte[] data)
 {
     blockType = (BlockType)stream.ReadByte();
     var sizeBuffer = stream.ReadBytes(2);
     var size = (ushort)(sizeBuffer[0] | sizeBuffer[1] << 8);
     data = stream.ReadBytes(size - 2);
 }
开发者ID:ha-tam,项目名称:TeraDamageMeter,代码行数:7,代码来源:_BlockHelper.cs

示例3: LoadFromStream

        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            if (Version == 1)
            {
                _CreationTime = stream.ReadBEUInt64();
                _ModificationTime = stream.ReadBEUInt64();
                TimeScale = stream.ReadBEUInt32();
                Duration = stream.ReadBEUInt64();
            }
            else // if(Version == 0)
            {
                _CreationTime = stream.ReadBEUInt32();
                _ModificationTime = stream.ReadBEUInt32();
                TimeScale = stream.ReadBEUInt32();
                Duration = stream.ReadBEUInt32();
            }
            _Rate = stream.ReadBEInt32();
            _Volume = stream.ReadBEInt16();
            Reserved = stream.ReadBytes(2 + (2 * 4));
            for (int i = 0; i < 9; i++) Matrix[i] = stream.ReadBEInt32();
            PreDefined = stream.ReadBytes(6 * 4);
            NextTrackID = stream.ReadBEUInt32();
        }
开发者ID:heksesang,项目名称:bmff,代码行数:25,代码来源:MovieHeaderBox.cs

示例4: WavLoader

		public WavLoader(Stream s)
		{
			while (s.Position < s.Length)
			{
				if ((s.Position & 1) == 1)
					s.ReadByte(); // Alignment

				var type = s.ReadASCII(4);
				switch (type)
				{
					case "RIFF":
						FileSize = s.ReadInt32();
						Format = s.ReadASCII(4);
						if (Format != "WAVE")
							throw new NotSupportedException("Not a canonical WAVE file.");
						break;
					case "fmt ":
						FmtChunkSize = s.ReadInt32();
						AudioFormat = s.ReadInt16();
						Type = (WaveType)AudioFormat;
						if (Type != WaveType.Pcm && Type != WaveType.ImaAdpcm)
							throw new NotSupportedException("Compression type is not supported.");
						Channels = s.ReadInt16();
						SampleRate = s.ReadInt32();
						ByteRate = s.ReadInt32();
						BlockAlign = s.ReadInt16();
						BitsPerSample = s.ReadInt16();

						s.ReadBytes(FmtChunkSize - 16);
						break;
					case "fact":
						{
							var chunkSize = s.ReadInt32();
							UncompressedSize = s.ReadInt32();
							s.ReadBytes(chunkSize - 4);
						}

						break;
					case "data":
						DataSize = s.ReadInt32();
						RawOutput = s.ReadBytes(DataSize);
						break;
					default:
						// Ignore unknown chunks
						{
							var chunkSize = s.ReadInt32();
							s.ReadBytes(chunkSize);
						}

						break;
				}
			}

			if (Type == WaveType.ImaAdpcm)
			{
				RawOutput = DecodeImaAdpcmData();
				BitsPerSample = 16;
			}
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:59,代码来源:WavLoader.cs

示例5: ShpTSReader

        public ShpTSReader(Stream stream)
        {
            stream.ReadUInt16();
            var width = stream.ReadUInt16();
            var height = stream.ReadUInt16();
            var size = new Size(width, height);
            var frameCount = stream.ReadUInt16();

            for (var i = 0; i < frameCount; i++)
                frames.Add(new FrameHeader(stream, size));

            for (var i = 0; i < frameCount; i++)
            {
                var f = frames[i];
                if (f.FileOffset == 0)
                    continue;

                stream.Position = f.FileOffset;

                // Uncompressed
                if (f.Format == 1 || f.Format == 0)
                    f.Data = stream.ReadBytes(f.Size.Width * f.Size.Height);

                // Uncompressed scanlines
                else if (f.Format == 2)
                {
                    f.Data = new byte[f.Size.Width * f.Size.Height];
                    for (var j = 0; j < f.Size.Height; j++)
                    {
                        var length = stream.ReadUInt16() - 2;
                        stream.Read(f.Data, f.Size.Width * j, length);
                    }
                }

                // RLE-zero compressed scanlines
                else if (f.Format == 3)
                {
                    f.Data = new byte[f.Size.Width * f.Size.Height];

                    for (var j = 0; j < f.Size.Height; j++)
                    {
                        var length = stream.ReadUInt16() - 2;
                        Format2.DecodeInto(stream.ReadBytes(length), f.Data, j * f.Size.Width);
                    }
                }
            }

            spriteFrames = Exts.Lazy(() => frames.Cast<ISpriteFrame>());
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:49,代码来源:ShpTSReader.cs

示例6: Decrypt

        public static Account Decrypt(Stream inputStream, ConsoleType consoleType)
        {
            var hmac = new HMACSHA1(consoleType == ConsoleType.Retail ? RetailKey : DevkitKey);
            var hash = inputStream.ReadBytes(16);
            var rc4Key = hmac.ComputeHash(hash);
            Array.Resize(ref rc4Key, 16);

            var rest = inputStream.ReadBytes(388);
            var body = RC4.Decrypt(rc4Key, rest);

            var compareBuffer = hmac.ComputeHash(body);
            if (!memcmp(hash, compareBuffer, 16))
                throw new InvalidDataException("Keys do not match");
            return ModelFactory.GetModel<Account>(body.Skip(8).ToArray());
        }
开发者ID:mousetwentytwo,项目名称:test,代码行数:15,代码来源:Account.cs

示例7: R8Frame

			public R8Frame(Stream s)
			{
				// Scan forward until we find some data
				var type = s.ReadUInt8();
				while (type == 0)
					type = s.ReadUInt8();

				var width = s.ReadInt32();
				var height = s.ReadInt32();
				var x = s.ReadInt32();
				var y = s.ReadInt32();

				Size = new Size(width, height);
				Offset = new int2(width / 2 - x, height / 2 - y);

				/*var imageOffset = */
				s.ReadInt32();
				var paletteOffset = s.ReadInt32();
				var bpp = s.ReadUInt8();
				if (bpp != 8)
					throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));

				var frameHeight = s.ReadUInt8();
				var frameWidth = s.ReadUInt8();
				FrameSize = new Size(frameWidth, frameHeight);

				// Skip alignment byte
				s.ReadUInt8();

				Data = s.ReadBytes(width * height);

				// Ignore palette
				if (type == 1 && paletteOffset != 0)
					s.Seek(520, SeekOrigin.Current);
			}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:35,代码来源:R8Loader.cs

示例8: Decode

        public DatabaseObject Decode(Stream source)
        {
            if (source == null) { throw new ArgumentNullException("source"); }

            // Create a binary reader that can be disposed without disposing the underlying stream.
            string type;
            string lenStr;
            using (BinaryReader reader = new BinaryReader(new DisposeProtectedStream(source)))
            {
                // First token is the type
                type = ReadToken(reader);

                // Second is the len
                lenStr = ReadToken(reader);
            }

            long len = -1;
            if(!Int64.TryParse(lenStr, out len)) {
                throw new InvalidDataException(String.Format("Invalid object, length token value is not an integer: {0}", lenStr));
            }

            // Should now be at the object body, read that in (for now)
            byte[] data = source.ReadBytes(len);
            return new DatabaseObject(DatabaseObjectTypeHelper.Parse(type), data);
        }
开发者ID:anurse,项目名称:Inversion,代码行数:25,代码来源:GitObjectCodec.cs

示例9: Decode

 public static String Decode(Stream stream)
 {
     int len = Int32EncodingLE.Decode(stream);
     if (len == -1) return null;
     byte[] buf = stream.ReadBytes(len);
     return Decode(buf);
 }
开发者ID:Egipto87,项目名称:DOOP.ec,代码行数:7,代码来源:StringEncoding.cs

示例10: Open

 public Stream Open(Stream stream)
 {
     stream.Seek(DataOffset, SeekOrigin.Begin);
     byte[] data;
     if (DataCompression == 0)
     {
         data = stream.ReadBytes(DataSize);
     }
     else
     {
         var dataBuffer = stream.ReadBytes(DataCompressedSize);
         var inflater = new Inflater(false);
         inflater.SetInput(dataBuffer);
         data = new Byte[DataSize];
         inflater.Inflate(data);
     }
     return new MemoryStream(data);
 }
开发者ID:wverkley,项目名称:Swg.Explorer,代码行数:18,代码来源:TREFile.cs

示例11: LoadFromStream

        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Predefined = stream.ReadBEUInt32();
            HandlerType = new FourCC(stream.ReadBytes(4));
            for (int i = 0; i < _Reserved.Length; i++) _Reserved[i] = stream.ReadBEUInt32();
            Name = stream.ReadNullTerminatedUTF8String();
        }
开发者ID:heksesang,项目名称:bmff,代码行数:9,代码来源:HandlerBox.cs

示例12: FileGroup

			public FileGroup(Stream reader, long offset)
			{
				var nameOffset = reader.ReadUInt32();
				/*   unknown  */ reader.ReadBytes(18);
				FirstFile = reader.ReadUInt32();
				LastFile = reader.ReadUInt32();

				reader.Seek(offset + (long)nameOffset, SeekOrigin.Begin);
				Name = reader.ReadASCIIZ();
			}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:10,代码来源:InstallShieldCABExtractor.cs

示例13: InstallShieldCABExtractor

        public InstallShieldCABExtractor(FileSystem context, string hdrFilename)
        {
            var fileGroups = new List<FileGroup>();
            var fileGroupOffsets = new List<uint>();

            hdrFile = context.Open(hdrFilename);
            this.context = context;

            // Strips archive number AND file extension
            Name = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", "");
            var signature = hdrFile.ReadUInt32();

            if (signature != 0x28635349)
                throw new InvalidDataException("Not an Installshield CAB package");

            commonHeader = new CommonHeader(hdrFile);
            cabDescriptor = new CabDescriptor(hdrFile, commonHeader);
            /*    unknown   */ hdrFile.ReadBytes(14);

            for (var i = 0U; i < MaxFileGroupCount; ++i)
                fileGroupOffsets.Add(hdrFile.ReadUInt32());

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset, SeekOrigin.Begin);
            directoryTable = new List<uint>();

            for (var i = 0U; i < cabDescriptor.DirectoryCount; ++i)
                directoryTable.Add(hdrFile.ReadUInt32());

            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    hdrFile.Seek((long)nextOffset + 4 + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
                    var descriptorOffset = hdrFile.ReadUInt32();
                    nextOffset = hdrFile.ReadUInt32();
                    hdrFile.Seek(descriptorOffset + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);

                    fileGroups.Add(new FileGroup(hdrFile, commonHeader.CabDescriptorOffset));
                }
            }

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2, SeekOrigin.Begin);
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; ++i)
                {
                    AddFileDescriptorToList(i);
                    var fileDescriptor = fileDescriptors[i];
                    var fullFilePath   = "{0}\\{1}\\{2}".F(fileGroup.Name, DirectoryName(fileDescriptor.DirectoryIndex), fileDescriptor.Filename);
                    index.Add(fullFilePath, i);
                }
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:54,代码来源:InstallShieldCABExtractor.cs

示例14: Read

		public static ApplicationData Read(Stream stream)
		{
			var blockSize = stream.ReadByte();
			if (blockSize <= 0)
			{
				return null;
			}

			var data = stream.ReadBytes(blockSize);
			return new ApplicationData((byte) blockSize, data);
		}
开发者ID:krabishe,项目名称:GIF89a.Transformation,代码行数:11,代码来源:ApplicationData.cs

示例15: WavLoader

        public WavLoader(Stream s)
        {
            while (s.Position < s.Length)
            {
                if ((s.Position & 1) == 1)
                    s.ReadByte(); // Alignment

                var type = s.ReadASCII(4);
                switch (type)
                {
                    case "RIFF":
                        FileSize = s.ReadInt32();
                        Format = s.ReadASCII(4);
                        if (Format != "WAVE")
                            throw new NotSupportedException("Not a canonical WAVE file.");
                        break;
                    case "fmt ":
                        FmtChunkSize = s.ReadInt32();
                        if (FmtChunkSize != 16)
                            throw new NotSupportedException("{0} fmt chunk size is not a supported encoding scheme.".F(FmtChunkSize));
                        AudioFormat = s.ReadInt16();
                        if (AudioFormat != 1)
                            throw new NotSupportedException("Non-PCM compression is not supported.");
                        Channels = s.ReadInt16();
                        SampleRate = s.ReadInt32();
                        ByteRate = s.ReadInt32();
                        BlockAlign = s.ReadInt16();
                        BitsPerSample = s.ReadInt16();
                        break;
                    case "data":
                        DataSize = s.ReadInt32();
                        RawOutput = s.ReadBytes(DataSize);
                        break;
                    default:
                        // Ignore unknown chunks
                        var chunkSize = s.ReadInt32();
                        s.ReadBytes(chunkSize);
                        break;
                }
            }
        }
开发者ID:TiriliPiitPiit,项目名称:OpenRA,代码行数:41,代码来源:WavLoader.cs


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