System.IO.MemoryStream.WriteByte C# (CSharp) Method

WriteByte() public method

public WriteByte ( byte value ) : void
value byte
return void
        public override void WriteByte(byte value)
        {
            if (!_isOpen)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_StreamClosed);
            }
            EnsureWriteable();

            if (_position >= _length)
            {
                int newLength = _position + 1;
                bool mustZero = _position > _length;
                if (newLength >= _capacity)
                {
                    bool allocatedNewArray = EnsureCapacity(newLength);
                    if (allocatedNewArray)
                    {
                        mustZero = false;
                    }
                }
                if (mustZero)
                {
                    Array.Clear(_buffer, _length, _position - _length);
                }
                _length = newLength;
            }
            _buffer[_position++] = value;
        }

Usage Example

Example #1
0
        public static void unescapeNAL(System.IO.MemoryStream _buf)
        {
            if (_buf.Position - _buf.Length < 2)
            {
                return;
            }
            System.IO.MemoryStream inb  = new System.IO.MemoryStream(_buf.ToArray());
            System.IO.MemoryStream outb = new System.IO.MemoryStream(_buf.ToArray());
            byte p1 = (byte)inb.ReadByte();

            outb.WriteByte(p1);
            byte p2 = (byte)inb.ReadByte();

            outb.WriteByte(p2);
            while (inb.Position < inb.Length)
            {
                byte b = (byte)inb.ReadByte();
                if (p1 != 0 || p2 != 0 || b != 3)
                {
                    outb.WriteByte(b);
                }
                p1 = p2;
                p2 = b;
            }
            _buf.SetLength(outb.Position);
        }
All Usage Examples Of System.IO.MemoryStream::WriteByte