示例#1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            long remaining    = Length - (UnderlyingStream.Position - PartialStart);
            int  actuallyRead = (int)Math.Min(remaining, count);

            if (actuallyRead < 0)
            {
                return(0);
            }

            return(UnderlyingStream.Read(buffer, offset, actuallyRead));
        }
示例#2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (Position >= Length)
            {
                return(0);
            }

            int toRead = (int)Math.Min(Length - Position, count);

            UnderlyingStream.Position = Position + Start;
            int bytesRead = UnderlyingStream.Read(buffer, offset, toRead);

            Position += bytesRead;
            return(bytesRead);
        }
示例#3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int  bytesRead = count;
            long max       = Length - Position;

            if (max < bytesRead)
            {
                bytesRead = (int)max;
            }

            UnderlyingStream.Read(buffer, offset, bytesRead);
            InternalPosition += bytesRead;

            return(bytesRead);
        }
示例#4
0
        public void BinaryListenTask( )
        {
            try
            {
                byte currentSequence = 0;
                while (IsRunning)
                {
                    if (UnderlyingStream.ReadByte( ) == DatagramHeaderInt)
                    {
                        byte sequence = ( byte )UnderlyingStream.ReadByte( );

                        if (sequence == currentSequence)
                        {
                            currentSequence++;
                        }
                        else
                        {
                            //Todo:???
                        }

                        BinaryDatagramType type = ( BinaryDatagramType )( byte )UnderlyingStream.ReadByte( );                               //todo:if not throw

                        byte crc = ( byte )UnderlyingStream.ReadByte( );

                        byte length = ( byte )UnderlyingStream.ReadByte( );

                        byte [] data = new byte[length];

                        UnderlyingStream.Read(data, 0, length);

                        if (data.CaluCrc8( ) == crc)
                        {
                            if (Datagram.Parse(type, data) is ReceiveDatagram datagram)
                            {
                                ReceiveQueue.Enqueue(datagram);
                            }
                        }
                        else
                        {
                            //todo:Warning?
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
        }
示例#5
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            try
            {
                int bytes = UnderlyingStream.Read(buffer, offset, count);
                _Position += bytes;

                Logger?.LogDebug($"StreamRequestWrapper: Read(buffer, {offset}, {count}) returned {bytes} Position: {this.Position} Length: {this.Length}");

                return(bytes);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            try
            {
                var readCount = UnderlyingStream.Read(buffer, offset, count);
                _position += readCount;
                return(readCount);
            }
            catch (Exception exception)
            {
                if (!ErrorIsRecoverable(exception))
                {
                    throw new ResumableStreamException("Unrecoverable read error occured", exception);
                }

                OnRecoverableError(new StreamErrorEventArgs(OperationType.Read, Position, count, exception));
                Recover(count);
                return(Read(buffer, offset, count));
            }
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (Direction == Direction.Write)
            {
                throw new InvalidOperationException("Incorrect direction");
            }
            byte[] underlying = new byte[count];
            int    read       = UnderlyingStream.Read(underlying, 0, count);

            for (int i = 0; i < read; i++)
            {
                if (Mode == EncryptionMode.Encrypt)
                {
                    buffer[i + offset] = encryptByte(underlying[i]);
                }
                else
                {
                    buffer[i + offset] = decryptByte(underlying[i]);
                }
            }
            return(read);
        }
示例#8
0
 public override int Read(byte[] buffer, int offset, int count)
 {
     ThrowIfDisposed();
     return(UnderlyingStream.Read(buffer, offset, count));
 }
示例#9
0
 public override int Read(byte[] buffer,
                          int offset,
                          int count)
 {
     return(UnderlyingStream.Read(buffer, offset, count));
 }