Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #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)
            {
            }
        }
Example #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);
        }
Example #8
0
 public override int Read(byte[] buffer, int offset, int count)
 {
     ThrowIfDisposed();
     return(UnderlyingStream.Read(buffer, offset, count));
 }
Example #9
0
 public override int Read(byte[] buffer,
                          int offset,
                          int count)
 {
     return(UnderlyingStream.Read(buffer, offset, count));
 }