protected byte[] ReadToByte(byte b, ValidateByteDelegate validator)
        {
            byte[] dest = null;
            if (this._dataCount == 0)
            {
                this.BufferMoreData();
            }
            int  num       = this._dataOffset + this._dataCount;
            int  srcOffset = this._dataOffset;
            int  index     = srcOffset;
            bool flag      = false;

            while (!flag)
            {
                bool flag2 = index == num;
                flag = !flag2 && (this._dataBuffer[index] == b);
                if (((validator != null) && !flag2) && (!flag && !validator(this._dataBuffer[index])))
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_InvalidDataReceived"));
                }
                if (flag2 || flag)
                {
                    int count = index - srcOffset;
                    if (dest == null)
                    {
                        dest = new byte[count];
                        StreamHelper.BufferCopy(this._dataBuffer, srcOffset, dest, 0, count);
                    }
                    else
                    {
                        int    length  = dest.Length;
                        byte[] buffer2 = new byte[length + count];
                        StreamHelper.BufferCopy(dest, 0, buffer2, 0, length);
                        StreamHelper.BufferCopy(this._dataBuffer, srcOffset, buffer2, length, count);
                        dest = buffer2;
                    }
                    this._dataOffset += count;
                    this._dataCount  -= count;
                    if (flag2)
                    {
                        this.BufferMoreData();
                        num       = this._dataOffset + this._dataCount;
                        srcOffset = this._dataOffset;
                        index     = srcOffset;
                    }
                    else if (flag)
                    {
                        this._dataOffset++;
                        this._dataCount--;
                    }
                }
                else
                {
                    index++;
                }
            }
            return(dest);
        }
 protected string ReadToChar(char ch, ValidateByteDelegate validator)
 {
     byte[] bytes = this.ReadToByte((byte)ch, validator);
     if (bytes == null)
     {
         return(null);
     }
     if (bytes.Length == 0)
     {
         return(string.Empty);
     }
     return(Encoding.ASCII.GetString(bytes));
 }
Exemplo n.º 3
0
        } // ReadToChar

        protected String ReadToChar(char ch, ValidateByteDelegate validator)
        {
            byte[] strBytes = ReadToByte((byte)ch, validator);
            if (strBytes == null)
            {
                return(null);
            }
            if (strBytes.Length == 0)
            {
                return(String.Empty);
            }

            String str = Encoding.ASCII.GetString(strBytes);

            return(str);
        } // ReadToChar
Exemplo n.º 4
0
        } // ReadToChar
 
        protected String ReadToChar(char ch, ValidateByteDelegate validator) 
        {
            byte[] strBytes = ReadToByte((byte)ch, validator); 
            if (strBytes == null)
                return null;
            if (strBytes.Length == 0)
                return String.Empty; 

            String str = Encoding.ASCII.GetString(strBytes); 
 
            return str;
        } // ReadToChar 
Exemplo n.º 5
0
        } /// ReadToByte
 
        protected byte[] ReadToByte(byte b, ValidateByteDelegate validator) 
        {
            byte[] readBytes = null; 

            // start at current position and return byte array consisting of bytes
            //   up to where we found the byte.
            if (_dataCount == 0) 
                BufferMoreData();
 
            int dataEnd = _dataOffset + _dataCount; // one byte past last valid byte 
            int startIndex = _dataOffset; // current position
            int endIndex = startIndex; // current index 

            bool foundByte = false;
            bool bufferEnd;
            while (!foundByte) 
            {
                InternalRemotingServices.RemotingAssert(endIndex <= dataEnd, "endIndex shouldn't pass dataEnd"); 
                bufferEnd = endIndex == dataEnd; 
                foundByte = !bufferEnd && (_dataBuffer[endIndex] == b);
 
                // validate character if necessary
                if ((validator != null) && !bufferEnd && !foundByte)
                {
                    if (!validator(_dataBuffer[endIndex])) 
                    {
                        throw new RemotingException( 
                            CoreChannel.GetResourceString( 
                                "Remoting_Http_InvalidDataReceived"));
                    } 
                }

                // we're at the end of the currently buffered data or we've found our byte
                if (bufferEnd || foundByte) 
                {
                    // store processed byte in the readBytes array 
                    int count = endIndex - startIndex; 
                    if (readBytes == null)
                    { 
                        readBytes = new byte[count];
                        StreamHelper.BufferCopy(_dataBuffer, startIndex, readBytes, 0, count);
                        }
                    else 
                    {
                        int oldSize = readBytes.Length; 
                        byte[] newBytes = new byte[oldSize + count]; 
                        StreamHelper.BufferCopy(readBytes, 0, newBytes, 0, oldSize);
                        StreamHelper.BufferCopy(_dataBuffer, startIndex, newBytes, oldSize, count); 
                        readBytes = newBytes;
                    }

                    // update data counters 
                    _dataOffset += count;
                    _dataCount -= count; 
 
                    if (bufferEnd)
                    { 
                        // we still haven't found the byte, so buffer more data
                        //   and keep looking.
                        BufferMoreData();
 
                        // reset indices
                        dataEnd = _dataOffset + _dataCount; // last valid byte 
                        startIndex = _dataOffset; // current position 
                        endIndex = startIndex; // current index
                    } 
                    else
                    if (foundByte)
                    {
                        // skip over the byte that we were looking for 
                        _dataOffset += 1;
                        _dataCount -= 1; 
                    } 
                }
                else 
                {
                    // still haven't found character or end of buffer, so advance position
                    endIndex++;
                } 
            }
 
            return readBytes; 
        } // ReadToByte
Exemplo n.º 6
0
        } /// ReadToByte

        protected byte[] ReadToByte(byte b, ValidateByteDelegate validator)
        {
            byte[] readBytes = null;

            // start at current position and return byte array consisting of bytes
            //   up to where we found the byte.
            if (_dataCount == 0)
            {
                BufferMoreData();
            }

            int dataEnd    = _dataOffset + _dataCount; // one byte past last valid byte
            int startIndex = _dataOffset;              // current position
            int endIndex   = startIndex;               // current index

            bool foundByte = false;
            bool bufferEnd;

            while (!foundByte)
            {
                InternalRemotingServices.RemotingAssert(endIndex <= dataEnd, "endIndex shouldn't pass dataEnd");
                bufferEnd = endIndex == dataEnd;
                foundByte = !bufferEnd && (_dataBuffer[endIndex] == b);

                // validate character if necessary
                if ((validator != null) && !bufferEnd && !foundByte)
                {
                    if (!validator(_dataBuffer[endIndex]))
                    {
                        throw new RemotingException(
                                  CoreChannel.GetResourceString(
                                      "Remoting_Http_InvalidDataReceived"));
                    }
                }

                // we're at the end of the currently buffered data or we've found our byte
                if (bufferEnd || foundByte)
                {
                    // store processed byte in the readBytes array
                    int count = endIndex - startIndex;
                    if (readBytes == null)
                    {
                        readBytes = new byte[count];
                        StreamHelper.BufferCopy(_dataBuffer, startIndex, readBytes, 0, count);
                    }
                    else
                    {
                        int    oldSize  = readBytes.Length;
                        byte[] newBytes = new byte[oldSize + count];
                        StreamHelper.BufferCopy(readBytes, 0, newBytes, 0, oldSize);
                        StreamHelper.BufferCopy(_dataBuffer, startIndex, newBytes, oldSize, count);
                        readBytes = newBytes;
                    }

                    // update data counters
                    _dataOffset += count;
                    _dataCount  -= count;

                    if (bufferEnd)
                    {
                        // we still haven't found the byte, so buffer more data
                        //   and keep looking.
                        BufferMoreData();

                        // reset indices
                        dataEnd    = _dataOffset + _dataCount; // last valid byte
                        startIndex = _dataOffset;              // current position
                        endIndex   = startIndex;               // current index
                    }
                    else
                    if (foundByte)
                    {
                        // skip over the byte that we were looking for
                        _dataOffset += 1;
                        _dataCount  -= 1;
                    }
                }
                else
                {
                    // still haven't found character or end of buffer, so advance position
                    endIndex++;
                }
            }

            return(readBytes);
        } // ReadToByte