Renci.SshNet.Common.SshDataStream.ToArray C# (CSharp) Method

ToArray() public method

Writes the stream contents to a byte array, regardless of the MemoryStream.Position.
If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned.
public ToArray ( ) : byte[]
return byte[]
        public override byte[] ToArray()
        {
            if (Capacity == Length)
            {
#if FEATURE_MEMORYSTREAM_GETBUFFER
                return GetBuffer();
#elif FEATURE_MEMORYSTREAM_TRYGETBUFFER
                ArraySegment<byte> buffer;
                if (TryGetBuffer(out buffer))
                    return buffer.Array;
#endif
            }
            return base.ToArray();
        }
    }

Usage Example

コード例 #1
0
        public void Load()
        {
            var target = new SftpAttrsResponse(_protocolVersion);
            var attributes = CreateSftpFileAttributes();
            var attributesBytes = attributes.GetBytes();

            var sshDataStream = new SshDataStream(4 + 1 + 4 + attributesBytes.Length);
            sshDataStream.Position = 4; // skip 4 bytes for SSH packet length
            sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs);
            sshDataStream.Write(_responseId);
            sshDataStream.Write(attributesBytes, 0, attributesBytes.Length);

            target.Load(sshDataStream.ToArray());

            Assert.IsNotNull(target.Attributes);
            Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
            Assert.AreEqual(_responseId, target.ResponseId);
            Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType);

            // check attributes in detail
            Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId);
            Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime);
            Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime);
            Assert.AreEqual(attributes.UserId, target.Attributes.UserId);
        }
All Usage Examples Of Renci.SshNet.Common.SshDataStream::ToArray