Renci.SshNet.Sftp.SftpFileStream.ReadByte C# (CSharp) Méthode

ReadByte() public méthode

Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
The stream does not support reading. Methods were called after the stream was closed. Read operation failed.
public ReadByte ( ) : int
Résultat int
        public override int ReadByte()
        {
            // Lock down the file stream while we do this.
            lock (_lock)
            {
                CheckSessionIsOpen();

                // Setup the object for reading.
                SetupRead();

                // Read more data into the internal buffer if necessary.
                if (_bufferPosition >= _bufferLen)
                {
                    _bufferPosition = 0;

                    var data = _session.RequestRead(_handle, (ulong)_position, (uint)_readBufferSize);

                    _bufferLen = data.Length;
                    Buffer.BlockCopy(data, 0, _readBuffer, 0, _readBufferSize);
                    _serverFilePosition = (ulong)_position;

                    if (_bufferLen == 0)
                    {
                        // We've reached EOF.
                        return -1;
                    }
                }

                // Extract the next byte from the buffer.
                ++_position;
                return _readBuffer[_bufferPosition++];
            }
        }

Usage Example

Exemple #1
0
 public void ReadByteTest()
 {
     SftpSession session = null; // TODO: Initialize to an appropriate value
     string path = string.Empty; // TODO: Initialize to an appropriate value
     FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value
     SftpFileStream target = new SftpFileStream(session, path, mode); // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.ReadByte();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }