C# MemoryStream.WriteByte的代码示例

通过代码示例来学习C# MemoryStream.WriteByte方法

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


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

MemoryStream.WriteByte的代码示例1 - Decompress()

    using System.IO;


        public static byte[] Decompress(byte[] input, bool useMagic = true)
        {
            if (input == null) throw new ArgumentNullException(nameof(input));
            using (var reader = new FileReader(new MemoryStream(input), true))
            {
                reader.SetByteOrder(true);
                reader.ReadSignature(4, "LZ77");

                reader.Position = 0;

                int i, j, k, r, c, z;
                uint flags, decompressedSize, currentSize = 0;

                byte[] temp = new byte[8];
                reader.Read(temp, 0, 8);

                if (temp[4] != 0x10)
                { reader.Dispose(); throw new Exception("Unsupported Compression Type!"); }

                decompressedSize = (BitConverter.ToUInt32(temp, 4)) >> 8;

                for (i = 0; i < N - F; i++) textBuffer[i] = 0xdf;
                r = N - F; flags = 7; z = 7;

                MemoryStream outFile = new MemoryStream();
                while (outFile.Length < decompressedSize)
                {
                    flags <<= 1;
                    z++;

                    if (z == 8)
                    {
                        if ((c = reader.ReadByte()) == -1) break;

                        flags = (uint)c;
                        z = 0;
                    }

                    if ((flags & 0x80) == 0)
                    {
                        if ((c = reader.ReadByte()) == reader.Length - 1) break;
                        if (currentSize < decompressedSize) outFile.WriteByte((byte)c);

                        textBuffer[r++] = (byte)c;
                        r &= (N - 1);
                        currentSize++;
                    }
                    else
                    {
                        if ((i = reader.ReadByte()) == -1) break;
                        if ((j = reader.ReadByte()) == -1) break;

                        j = j | ((i << 8) & 0xf00);
                        i = ((i >> 4) & 0x0f) + threshold;
                        for (k = 0; k <= i; k++)
                        {
                            c = textBuffer[(r - j - 1) & (N - 1)];
                            if (currentSize < decompressedSize) outFile.WriteByte((byte)c); textBuffer[r++] = (byte)c; r &= (N - 1); currentSize++;
                        }
                    }
                }
                return outFile.ToArray();
            }
            return input;
        }
    

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

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

MemoryStream.WriteByte的代码示例2 - urlDecodeToBytes()

    using System.IO;

    private static byte[] urlDecodeToBytes (byte[] bytes, int offset, int count)
    {
      using (var buff = new MemoryStream ()) {
        var end = offset + count - 1;
        for (var i = offset; i <= end; i++) {
          var b = bytes[i];

          var c = (char) b;
          if (c == '%') {
            if (i > end - 2)
              break;

            var num = getNumber (bytes, i + 1, 2);
            if (num == -1)
              break;

            buff.WriteByte ((byte) num);
            i += 2;

            continue;
          }

          if (c == '+') {
            buff.WriteByte ((byte) ' ');
            continue;
          }

          buff.WriteByte (b);
        }

        buff.Close ();
        return buff.ToArray ();
      }
    }
    

开发者ID:ntminer,项目名称:NtMiner,代码行数:36,代码来源:HttpUtility.cs

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

MemoryStream.WriteByte的代码示例3 - CreateCursor()

    using System.IO;

        public static Cursor CreateCursor(double rx, double ry, SolidColorBrush brush, Pen pen)
        {
            var vis = new DrawingVisual();
            using (var dc = vis.RenderOpen())
            {
                dc.DrawRectangle(brush, new Pen(Brushes.Black, 0.1), new Rect(0, 0, rx, ry));
                dc.Close();
            }
            var rtb = new RenderTargetBitmap(64, 64, 96, 96, PixelFormats.Pbgra32);
            rtb.Render(vis);

            using (var ms1 = new MemoryStream())
            {
                var penc = new PngBitmapEncoder();
                penc.Frames.Add(BitmapFrame.Create(rtb));
                penc.Save(ms1);

                var pngBytes = ms1.ToArray();
                var size = pngBytes.GetLength(0);

                //.cur format spec http://en.wikipedia.org/wiki/ICO_(file_format)
                using (var ms = new MemoryStream()) {
                    {//ICONDIR Structure
                        ms.Write(BitConverter.GetBytes((Int16)0), 0, 2);//Reserved must be zero; 2 bytes
                        ms.Write(BitConverter.GetBytes((Int16)2), 0, 2);//image type 1 = ico 2 = cur; 2 bytes
                        ms.Write(BitConverter.GetBytes((Int16)1), 0, 2);//number of images; 2 bytes
                    }

                    {//ICONDIRENTRY structure
                        ms.WriteByte(32); //image width in pixels
                        ms.WriteByte(32); //image height in pixels

                        ms.WriteByte(0); //Number of Colors in the color palette. Should be 0 if the image doesn't use a color palette
                        ms.WriteByte(0); //reserved must be 0

                        ms.Write(BitConverter.GetBytes((Int16)(rx / 2.0)), 0, 2);//2 bytes. In CUR format: Specifies the horizontal coordinates of the hotspot in number of pixels from the left.
                        ms.Write(BitConverter.GetBytes((Int16)(ry / 2.0)), 0, 2);//2 bytes. In CUR format: Specifies the vertical coordinates of the hotspot in number of pixels from the top.

                        ms.Write(BitConverter.GetBytes(size), 0, 4);//Specifies the size of the image's data in bytes
                        ms.Write(BitConverter.GetBytes((Int32)22), 0, 4);//Specifies the offset of BMP or PNG data from the beginning of the ICO/CUR file
                    }

                    ms.Write(pngBytes, 0, size);//write the png data.
                    ms.Seek(0, SeekOrigin.Begin);
                    return new Cursor(ms);
                }
            }
        }
    

开发者ID:Dijji,项目名称:FileMeta,代码行数:50,代码来源:IconFactory.cs

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

MemoryStream.WriteByte的代码示例4 - InitializeMStream()

    using System.IO;
        #endregion

        #region Methods
        /// 
        /// Initialize stream and hexeditor
        /// 
        private void InitializeMStream(HexEditor hexeditor, byte[] findData = null)
        {
            hexeditor.CloseProvider();

            var ms = new MemoryStream(1);

            if (findData is not null && findData.Length > 0)
                foreach (var b in findData)
                    ms.WriteByte(b);
            else
                ms.WriteByte(0);

            hexeditor.Stream = ms;
        }
    

开发者ID:abbaye,项目名称:WpfHexEditorControl,代码行数:21,代码来源:FindReplaceWindow.xaml.cs

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

MemoryStream.WriteByte的代码示例5 - InitializeMStream()

    using System.IO;

        /// 
        /// Initialize stream and hexeditor
        /// 
        private void InitializeMStream(byte[] findData = null)
        {
            FindHexEdit.CloseProvider();

            _findMs = new MemoryStream(1);

            if (findData is not null && findData.Length > 0)
                foreach (var b in findData)
                    _findMs.WriteByte(b);
            else
                _findMs.WriteByte(0);

            FindHexEdit.Stream = _findMs;
        }
    

开发者ID:abbaye,项目名称:WpfHexEditorControl,代码行数:19,代码来源:FindWindow.xaml.cs

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

MemoryStream.WriteByte的代码示例6 - AesStream_Invalid_Password()

    using System.IO;

        /// 
        /// Test whether AesStream can handle stream where bytes 32-64 are empty.
        /// 
        [Fact]
        public void AesStream_Invalid_Password()
        {
            // stream of 8192 bytes where bytes 32 to 64 is empty. 
            using (var memoryStream = new MemoryStream())
            {
                // 1st byte to indicate the stream is encrypted
                memoryStream.WriteByte(1);

                // next 16 bytes contain salt
                var salt = new byte[16];
                using (var rng = RandomNumberGenerator.Create())
                {
                    rng.GetBytes(salt);
                }
                memoryStream.Write(salt, 0, salt.Length);

                // remaining (8192 - 17) bytes are empty
                var emptyContent = new byte[8175];
                memoryStream.Write(emptyContent, 0, emptyContent.Length);

                // reset the stream position to 0
                memoryStream.Position = 0;

                using (var crypto = new AesStream("password", memoryStream))
                {
                    // 1st page is hidden, so AesStream.Length returns (stream.Length - PAGE_SIZE)
                    Assert.Equal(0, crypto.Length);

                    // AesStream should add padding to the underlying stream to make its size equivalent to PAGE_SIZE
                    Assert.Equal(8192, memoryStream.Length);

                    // AesStream should fill bytes 32-64 with encrypted 1s
                    var checkBytes = new byte[32];
                    var cryptoReader = typeof(AesStream)
                        .GetField("_reader", BindingFlags.Instance | BindingFlags.NonPublic)
                        .GetValue(crypto) as CryptoStream;
                    
                    memoryStream.Position = 32;
                    cryptoReader.Read(checkBytes, 0, checkBytes.Length);
                    Assert.All(checkBytes, b => Assert.Equal(1, b));
                }
            }
        }
    

开发者ID:mbdavid,项目名称:LiteDB,代码行数:49,代码来源:Aes_Tests.cs

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

MemoryStream.WriteByte的代码示例7 - ReadCString()

    using System.IO;

        /// 
        /// Reading string until find \0 at end
        /// 
        public string ReadCString()
        {
            // first try read CString in current segment
            if (this.TryReadCStringCurrentSegment(out var value))
            {
                return value;
            }
            else
            {
                using (var mem = new MemoryStream())
                {
                    // copy all first segment 
                    var initialCount = _current.Count - _currentPosition;

                    mem.Write(_current.Array, _current.Offset + _currentPosition, initialCount);

                    this.MoveForward(initialCount);

                    // and go to next segment
                    while (_current[_currentPosition] != 0x00 && _isEOF == false)
                    {
                        mem.WriteByte(_current[_currentPosition]);

                        this.MoveForward(1);
                    }

                    this.MoveForward(1); // +1 to '\0'

                    return StringEncoding.UTF8.GetString(mem.ToArray());
                }
            }
        }
    

开发者ID:mbdavid,项目名称:LiteDB,代码行数:37,代码来源:BufferReader.cs

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

MemoryStream.WriteByte的代码示例8 - BinaryToText()

    using System.IO;

        public static string BinaryToText(string binary)
        {
            binary = Regex.Replace(binary, @"[^01]", "");

            using (MemoryStream stream = new MemoryStream())
            {
                for (int i = 0; i + 8 <= binary.Length; i += 8)
                {
                    stream.WriteByte(BinaryToByte(binary.Substring(i, 8)));
                }

                return Encoding.UTF8.GetString(stream.ToArray());
            }
        }
    

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

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

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