public override int Read(byte[] buffer, int offset, int count) { int bytesRead = 0; while (!_bFoundEnd && (count > 0)) { // see if we need to start reading a new chunk if (_bytesLeft == 0) { // this loop stops when the end of line is found for (;;) { byte b = (byte)_inputStream.ReadByte(); // see if this is the end of the length if (b == '\r') { // This had better be '\n' if ((char)_inputStream.ReadByte() != '\n') { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Http_ChunkedEncodingError")); } else { break; // we've finished reading the length } } else { int value = HttpChannelHelper.CharacterHexDigitToDecimal(b); // make sure value is a hex-digit if ((value < 0) || (value > 15)) { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Http_ChunkedEncodingError")); } // update _bytesLeft value to account for new digit on the right _bytesLeft = (_bytesLeft * 16) + value; } } if (_bytesLeft == 0) { // read off trailing headers and end-line String trailerHeader; do { trailerHeader = _inputStream.ReadToEndOfLine(); } while (!(trailerHeader.Length == 0)); _bFoundEnd = true; } } if (!_bFoundEnd) { int readCount = min(_bytesLeft, count); int bytesReadThisTime = _inputStream.Read(buffer, offset, readCount); if (bytesReadThisTime <= 0) { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Http_ChunkedEncodingError")); } _bytesLeft -= bytesReadThisTime; count -= bytesReadThisTime; offset += bytesReadThisTime; bytesRead += bytesReadThisTime; // see if the end of the chunk was found if (_bytesLeft == 0) { // read off "\r\n" char ch = (char)_inputStream.ReadByte(); if (ch != '\r') { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Http_ChunkedEncodingError")); } ch = (char)_inputStream.ReadByte(); if (ch != '\n') { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Http_ChunkedEncodingError")); } } } } // while (count > 0) return(bytesRead); } // Read
public override int Read(byte[] buffer, int offset, int count) { int num = 0; while (!this._bFoundEnd && (count > 0)) { if (this._bytesLeft == 0) { while (true) { byte b = (byte)this._inputStream.ReadByte(); if (b == 13) { if (((ushort)this._inputStream.ReadByte()) != 10) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError")); } break; } int num3 = HttpChannelHelper.CharacterHexDigitToDecimal(b); if ((num3 < 0) || (num3 > 15)) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError")); } this._bytesLeft = (this._bytesLeft * 0x10) + num3; } if (this._bytesLeft == 0) { while (this._inputStream.ReadToEndOfLine().Length != 0) { } this._bFoundEnd = true; } } if (!this._bFoundEnd) { int num4 = Math.Min(this._bytesLeft, count); int num5 = this._inputStream.Read(buffer, offset, num4); if (num5 <= 0) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError")); } this._bytesLeft -= num5; count -= num5; offset += num5; num += num5; if (this._bytesLeft != 0) { continue; } char ch = (char)this._inputStream.ReadByte(); if (ch != '\r') { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError")); } ch = (char)this._inputStream.ReadByte(); if (ch != '\n') { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError")); } } } return(num); }