当前位置: 首页>>代码示例>>C#>>正文


C# SizeExceededAction类代码示例

本文整理汇总了C#中SizeExceededAction的典型用法代码示例。如果您正苦于以下问题:C# SizeExceededAction类的具体用法?C# SizeExceededAction怎么用?C# SizeExceededAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SizeExceededAction类属于命名空间,在下文中一共展示了SizeExceededAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadLineEventArgs

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="buffer">Line buffer.</param>
        /// <param name="exceededAction">Specifies how line-reader behaves when maximum line size exceeded.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null reference.</exception>
        public ReadLineEventArgs(byte[] buffer,SizeExceededAction exceededAction)
        {
            if(buffer == null){
                throw new ArgumentNullException("buffer");
            }

            m_pBuffer        = buffer;
            m_ExceededAction = exceededAction;
        }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:15,代码来源:ReadLineEventArgs.cs

示例2: _ToStreamReader

 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="streamHelper">Reference to StreamHelper.</param>
 /// <param name="storeStream">Stream where to store readed data.</param>
 /// <param name="maxSize">Maximum number of bytes to read.</param>
 /// <param name="exceededAction">Specifies how this method behaves when maximum size exceeded.</param>
 /// <param name="callback">Callback what will be called if asynchronous reading compltes.</param>
 /// <param name="tag">User data.</param>
 public _ToStreamReader(StreamHelper streamHelper,Stream storeStream,int maxSize,SizeExceededAction exceededAction,ReadToStreamCallback callback,object tag)
 {
     m_pStreamHelper   = streamHelper;
     m_pStoreStream    = storeStream;
     m_pBufferedStream = new BufferedStream(m_pStoreStream,32000);
     m_MaxSize         = maxSize;
     m_ExceededAction  = exceededAction;
     m_pCallback       = callback;
     m_pTag            = tag;
     m_pBuffer         = new byte[32000];
     m_pLineBuffer     = new byte[4096];
 }
开发者ID:iraychen,项目名称:ourmsg,代码行数:21,代码来源:StreamHelper.cs

示例3: ReadPeriodTerminated

        /// <summary>
        /// Reads period terminated data from source stream. Reads data while gets single period on line,
        /// what is data terminator.
        /// </summary>
        /// <param name="storeStream">Stream where to store readed data.</param>
        /// <param name="maxSize">Maximum number of bytes to read.</param>
        /// <param name="exceededAction">Specifies how this method behaves when maximum size exceeded.</param>
        /// <returns>Returns number of bytes written to <b>storeStream</b>.</returns>
        /// <exception cref="ArgumentNullException">Raised when <b>storeStream</b> is null.</exception>
        /// <exception cref="ArgumentException">Raised when <b>maxSize</b> less than 1.</exception>
        /// <exception cref="InvalidOperationException">Raised when there already is pending read operation.</exception>
        /// <exception cref="LineSizeExceededException">Raised when maximum allowed line size has exceeded.</exception>
        /// <exception cref="DataSizeExceededException">Raised when maximum allowed data size has exceeded.</exception>
        /// <exception cref="IncompleteDataException">Raised when source stream was reached end of stream and data is not period terminated.</exception>
        public int ReadPeriodTerminated(Stream storeStream,int maxSize,SizeExceededAction exceededAction)
        {
            if(storeStream == null){
                throw new ArgumentNullException("storeStream");
            }
            lock(this){
                if(m_IsReadActive){
                    throw new InvalidOperationException("There is pending read operation, multiple read operations not allowed !");
                }
                else{
                    m_IsReadActive = true;
                }
            }

            try{
                BufferedStream bufferedStoreStream = new BufferedStream(storeStream,32000);
                bool lineSizeExceeded   = false;
                bool isPeriodTerminated = false;
                int  totalReadedCount   = 0;
                int  readedCount        = 0;
                int  rawReadedCount     = 0;

                // Just break reading at once if maximum allowed line or data size exceeded.
                if(exceededAction == SizeExceededAction.ThrowException){
                    try{
                        // Read first line.
                        readedCount = this.ReadLineInternal(m_pLineBuffer,SizeExceededAction.JunkAndThrowException,out rawReadedCount,false);
                    }
                    catch(LineSizeExceededException x){
                        string dummy = x.Message;
                        lineSizeExceeded = true;
                    }
                    while(rawReadedCount != 0){
                        totalReadedCount += rawReadedCount;

                        // We have data terminator "<CRLF>.<CRLF>".
                        if(readedCount == 1 && m_pLineBuffer[0] == '.'){
                            isPeriodTerminated = true;
                            break;
                        }
                        // If line starts with period(.), first period is removed.
                        else if(m_pLineBuffer[0] == '.'){
                            // Maximum allowed line or data size exceeded.
                            if(lineSizeExceeded || totalReadedCount > maxSize){
                                // Junk data
                            }
                            // Write readed line to store stream.
                            else{
                                bufferedStoreStream.Write(m_pLineBuffer,1,readedCount - 1);
                                bufferedStoreStream.Write(m_LineBreak,0,m_LineBreak.Length);
                            }
                        }
                        // Normal line.
                        else{
                            // Maximum allowed line or data size exceeded.
                            if(lineSizeExceeded || totalReadedCount > maxSize){
                                // Junk data
                            }
                            // Write readed line to store stream.
                            else{
                                bufferedStoreStream.Write(m_pLineBuffer,0,readedCount);
                                bufferedStoreStream.Write(m_LineBreak,0,m_LineBreak.Length);
                            }
                        }

                        try{
                            // Read next line.
                            readedCount = this.ReadLineInternal(m_pLineBuffer,SizeExceededAction.JunkAndThrowException,out rawReadedCount,false);
                        }
                        catch(LineSizeExceededException x){
                            string dummy = x.Message;
                            lineSizeExceeded = true;
                        }
                    }
                }
                // Read and junk all data if maximum allowed line or data size exceeded.
                else{
                    // Read first line.
                    readedCount = this.ReadLineInternal(m_pLineBuffer,SizeExceededAction.JunkAndThrowException,out rawReadedCount,false);
                    while(rawReadedCount != 0){
                        totalReadedCount += rawReadedCount;

                        // We have data terminator "<CRLF>.<CRLF>".
                        if(readedCount == 1 && m_pLineBuffer[0] == '.'){
                            isPeriodTerminated = true;
                            break;
//.........这里部分代码省略.........
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:101,代码来源:StreamHelper.cs

示例4: ReadLineInternal

        /// <summary>
        /// Reads line from source stream and stores to specified buffer. This method accepts LF or CRLF lines.
        /// </summary>
        /// <param name="buffer">Buffer where to store line data.</param>
        /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
        /// <param name="readedCount">Returns how many bytes this method actually readed form source stream.</param>
        /// <param name="log">Specifies if read line is logged.</param>
        /// <returns>Returns number of bytes stored to buffer, returns -1 if end of stream reached and no more data.</returns>
        /// <exception cref="InvalidOperationException">Raised when there already is pending read operation.</exception>
        /// <exception cref="LineSizeExceededException">Raised when maximum allowed line size has exceeded.</exception>
        public int ReadLineInternal(byte[] buffer,SizeExceededAction exceededAction,out int readedCount,bool log)
        {
            readedCount = 0;
            int bufferSize  = buffer.Length;
            int posInBuffer = 0;
            int currentByte = 0;

            /* Because performance gain we need todo,2 while, buffered and non buffered read.
               Each if clause in this while adds about 5% cpu.
            */

            #region Buffered

            if(m_IsReadBuffered){
                while(true){
                    //--- Read byte -----------------------------------------------------
                    if(m_ReadBufferOffset >= m_ReadBufferEndPos){
                        m_ReadBufferEndPos = m_pStream.Read(m_pReadBuffer,0,32000);
                        m_ReadBufferOffset = 0;

                        // We reached end of stream.
                        if(m_ReadBufferEndPos == 0){
                            break;
                        }
                    }

                    currentByte = m_pReadBuffer[m_ReadBufferOffset];
                    m_ReadBufferOffset++;
                    readedCount++;
                    //-------------------------------------------------------------------

                    // We have LF.
                    if(currentByte == '\n'){
                        break;
                    }
                    // We just skip all CR.
                    else if(currentByte == '\r'){
                    }
                    // Maximum allowed line size exceeded.
                    else if(readedCount > bufferSize){
                        if(exceededAction == SizeExceededAction.ThrowException){
                            throw new LineSizeExceededException();
                        }
                    }
                    // Store readed byte.
                    else{
                        buffer[posInBuffer] = (byte)currentByte;
                        posInBuffer++;
                    }
                }
            }

            #endregion

            #region No-buffered

            else{
                while(true){
                    // Read byte
                    currentByte = m_pStream.ReadByte();
                    // We reached end of stream, no more data.
                    if(currentByte == -1){
                        break;
                    }
                    readedCount++;

                    // We have LF.
                    if(currentByte == '\n'){
                        break;
                    }
                    // We just skip all CR.
                    else if(currentByte == '\r'){
                    }
                    // Maximum allowed line size exceeded.
                    else if(readedCount > bufferSize){
                        if(exceededAction == SizeExceededAction.ThrowException){
                            throw new LineSizeExceededException();
                        }
                    }
                    // Store readed byte.
                    else{
                        buffer[posInBuffer] = (byte)currentByte;
                        posInBuffer++;
                    }
                }
            }

            #endregion

            // We are end of stream, no more data.
//.........这里部分代码省略.........
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:101,代码来源:StreamHelper.cs

示例5: ReadLine

        /// <summary>
        /// Reads line from source stream.
        /// </summary>
        /// <param name="encoding">Encoding to use to decode line.</param>
        /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
        /// <returns>Returns readed line with specified encoding or null if end of stream reached and no more data.</returns>
        /// <exception cref="ArgumentNullException">Raised when <b>encoding</b> is null.</exception>
        /// <exception cref="InvalidOperationException">Raised when there already is pending read operation.</exception>
        /// <exception cref="LineSizeExceededException">Raised when maximum allowed line size has exceeded.</exception>
        public string ReadLine(Encoding encoding,SizeExceededAction exceededAction)
        {
            if(encoding == null){
                throw new ArgumentNullException("encoding");
            }

            int readedCount = ReadLine(m_pLineBuffer,exceededAction);
            if(readedCount == -1){
                return null;
            }
            else{
                return encoding.GetString(m_pLineBuffer,0,readedCount);
            }
        }
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:23,代码来源:StreamHelper.cs

示例6: ReadPeriodTerminatedAsyncOP

            /// <summary>
            /// Default constructor.
            /// </summary>
            /// <param name="stream">Stream wehre to sore readed data.</param>
            /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
            /// <param name="exceededAction">Specifies how period-terminated reader behaves when <b>maxCount</b> exceeded.</param>
            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
            public ReadPeriodTerminatedAsyncOP(Stream stream,long maxCount,SizeExceededAction exceededAction)
            {
                if(stream == null){
                    throw new ArgumentNullException("stream");
                }

                m_pStream        = stream;
                m_MaxCount       = maxCount;
                m_ExceededAction = exceededAction;

                m_pReadLineOP = new ReadLineAsyncOP(new byte[32000],exceededAction);
                m_pReadLineOP.Completed += new EventHandler<EventArgs<ReadLineAsyncOP>>(m_pReadLineOP_Completed);
            }
开发者ID:grumpycatsaysno,项目名称:SitefinityMailServer,代码行数:20,代码来源:SmartStream.cs

示例7: BeginReadHeader

        /// <summary>
        /// Begins an asynchronous header reading from the source stream.
        /// </summary>
        /// <param name="storeStream">Stream where to store readed header.</param>
        /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
        /// <param name="exceededAction">Specifies action what is done if <b>maxCount</b> number of bytes has exceeded.</param>
        /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
        /// <param name="state">An object that contains any additional user-defined data.</param>
        /// <returns>An IAsyncResult that represents the asynchronous call.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>storeStream</b> is null reference.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        public IAsyncResult BeginReadHeader(Stream storeStream,
                                            int maxCount,
                                            SizeExceededAction exceededAction,
                                            AsyncCallback callback,
                                            object state)
        {
            if (m_IsDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (storeStream == null)
            {
                throw new ArgumentNullException("storeStream");
            }
            if (maxCount < 0)
            {
                throw new ArgumentException("Argument 'maxCount' must be >= 0.");
            }

            return new ReadToTerminatorAsyncOperation(this,
                                                      "",
                                                      storeStream,
                                                      maxCount,
                                                      exceededAction,
                                                      callback,
                                                      state);
        }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:39,代码来源:SmartStream.cs

示例8: ReadToTerminatorAsyncOperation

            /// <summary>
            /// Default constructor.
            /// </summary>
            /// <param name="owner">Owner stream.</param>
            /// <param name="terminator">Data terminator.</param>
            /// <param name="storeStream">Stream where to store readed header.</param>
            /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
            /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
            /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
            /// <param name="asyncState">User-defined object that qualifies or contains information about an asynchronous operation.</param>
            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b>,<b>terminator</b> or <b>storeStream</b> is null reference.</exception>
            public ReadToTerminatorAsyncOperation(SmartStream owner,
                                                  string terminator,
                                                  Stream storeStream,
                                                  long maxCount,
                                                  SizeExceededAction exceededAction,
                                                  AsyncCallback callback,
                                                  object asyncState)
            {
                if (owner == null)
                {
                    throw new ArgumentNullException("owner");
                }
                if (terminator == null)
                {
                    throw new ArgumentNullException("terminator");
                }
                if (storeStream == null)
                {
                    throw new ArgumentNullException("storeStream");
                }
                if (maxCount < 0)
                {
                    throw new ArgumentException("Argument 'maxCount' must be >= 0.");
                }

                m_pOwner = owner;
                m_Terminator = terminator;
                m_pTerminatorBytes = Encoding.ASCII.GetBytes(terminator);
                m_pStoreStream = storeStream;
                m_MaxCount = maxCount;
                m_SizeExceededAction = exceededAction;
                m_pAsyncCallback = callback;
                m_pAsyncState = asyncState;

                m_pAsyncWaitHandle = new AutoResetEvent(false);

                m_pLineBuffer = new byte[Workaround.Definitions.MaxStreamLineLength];

                // Start reading data.
                m_pOwner.BeginReadLine(m_pLineBuffer,
                                       0,
                                       m_pLineBuffer.Length - 2,
                                       m_SizeExceededAction,
                                       ReadLine_Completed,
                                       null);
            }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:57,代码来源:SmartStream.cs

示例9: BeginReadLine

        /// <summary>
        /// Starts reading line from source stream.
        /// </summary>
        /// <param name="buffer">Buffer where to store line data.</param>
        /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
        /// <param name="tag">User data.</param>
        /// <param name="callback">Callback to be called whan asynchronous operation completes.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>buffer</b> is null.</exception>
        /// <exception cref="InvalidOperationException">Raised when there already is pending read operation.</exception>
        public void BeginReadLine(byte[] buffer,SizeExceededAction exceededAction,object tag,ReadLineCallback callback)
        {
            if(buffer == null){
                throw new ArgumentNullException("buffer");
            }
            lock(this){
                if(m_IsReadActive){
                    throw new InvalidOperationException("There is pending read operation, multiple read operations not allowed !");
                }
                m_IsReadActive = false;
            }

            BeginReadLineInternal(buffer,exceededAction,tag,callback,true,true);
        }
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:23,代码来源:StreamHelper.cs

示例10: BeginReadLineInternal

        /// <summary>
        /// Starts reading line from source stream. This method does not do any checks and read locks.
        /// </summary>
        /// <param name="buffer">Buffer where to store line data.</param>
        /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
        /// <param name="tag">User data.</param>
        /// <param name="callback">Callback to be called whan asynchronous operation completes.</param>
        /// <param name="unlockRead">Specifies if read lock is released.</param>
        /// <param name="log">User data.</param>
        private void BeginReadLineInternal(byte[] buffer,SizeExceededAction exceededAction,object tag,ReadLineCallback callback,bool unlockRead,bool log)
        {
            m_pRLine_LineBuffer      = buffer;
            m_RLine_ExceedAction     = exceededAction;
            m_pRLine_Tag             = tag;
            m_pRLine_Callback        = callback;
            m_RLine_LineBufferOffset = 0;
            m_RLine_TotalReadedCount = 0;
            m_RLine_LineBufferSize   = buffer.Length;
            m_RLine_UnlockRead       = unlockRead;
            m_RLine_Log              = log;

            if(this.IsReadBuffered){
                DoReadLine_Buffered();
            }
            else{
                m_pStream.BeginRead(m_pRLine_ByteBuffer,0,1,new AsyncCallback(this.OnReadByte_Completed),null);
            }
        }
开发者ID:janemiceli,项目名称:authenticated_mail_server,代码行数:28,代码来源:StreamHelper.cs

示例11: _ToStreamReader

 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="streamHelper">Reference to StreamHelper.</param>
 /// <param name="storeStream">Stream where to store readed data.</param>
 /// <param name="maxSize">Maximum number of bytes to read.</param>
 /// <param name="exceededAction">Specifies how this method behaves when maximum size exceeded.</param>
 /// <param name="callback">Callback what will be called if asynchronous reading compltes.</param>
 /// <param name="tag">User data.</param>
 public _ToStreamReader(StreamHelper streamHelper,
                        Stream storeStream,
                        int maxSize,
                        SizeExceededAction exceededAction,
                        ReadToStreamCallback callback,
                        object tag)
 {
     m_pStreamHelper = streamHelper;
     m_pStoreStream = storeStream;
     m_pBufferedStream = new BufferedStream(m_pStoreStream, Workaround.Definitions.MaxStreamLineLength);
     m_MaxSize = maxSize;
     m_ExceededAction = exceededAction;
     m_pCallback = callback;
     m_pTag = tag;
     m_pBuffer = new byte[Workaround.Definitions.MaxStreamLineLength];
     m_pLineBuffer = new byte[4096];
 }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:26,代码来源:StreamHelper.cs

示例12: ReadLine

            /// <summary>
            /// Reads binary line and stores it to the specified buffer.
            /// </summary>
            /// <param name="buffer">Buffer where to store line data.</param>
            /// <param name="offset">Start offset in the buffer.</param>
            /// <param name="count">Maximum number of bytes store to the buffer.</param>
            /// <param name="exceededAction">Specifies how reader acts when line buffer too small.</param>
            /// <param name="rawBytesReaded">Gets raw number of bytes readed from source.</param>
            /// <returns>Returns number of bytes stored to <b>buffer</b> or -1 if end of stream reached.</returns>
            /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
            /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null.</exception>
            /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
            /// <exception cref="LineSizeExceededException">Is raised when line is bigger than <b>buffer</b> can store.</exception>
            public override int ReadLine(byte[] buffer,int offset,int count,SizeExceededAction exceededAction,out int rawBytesReaded)
            {
                rawBytesReaded = 0;

                // We are at the end of body or "body part".
                if(m_State == State.Finished || m_State == State.NextWaited){
                    return -1;
                }
                // Read next line.
                else{
                    int readedCount = m_pReader.ReadLine(buffer,offset,count,exceededAction,out rawBytesReaded);
                    // End of stream reached, no more data.
                    if(readedCount == -1){
                        m_State = State.Finished;

                        return -1;
                    }
                    // For multipart we must check boundary tags.
                    else if(!string.IsNullOrEmpty(m_Boundary) && readedCount > 2 && buffer[0] == '-'){
                        string line = Encoding.Default.GetString(buffer,0,readedCount);

                        // Boundray end-tag reached, no more "body parts".
                        if(line == "--" + m_Boundary + "--"){
                            m_State = State.Finished;

                            return -1;
                        }
                        // Boundary start-tag reached, wait for this.Next() call.
                        else if(line == "--" + m_Boundary){
                            m_State = State.NextWaited;

                            return -1;
                        }
                    }

                    return readedCount;
                }
            }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:51,代码来源:MIME_MultipartBody.cs

示例13: ReadLine

        /// <summary>
        /// Reads binary line and stores it to the specified buffer.
        /// </summary>
        /// <param name="buffer">Buffer where to store line data.</param>
        /// <param name="offset">Start offset in the buffer.</param>
        /// <param name="count">Maximum number of bytes store to the buffer.</param>
        /// <param name="exceededAction">Specifies how reader acts when line buffer too small.</param>
        /// <param name="rawBytesReaded">Gets raw number of bytes readed from source.</param>
        /// <returns>Returns number of bytes stored to <b>buffer</b> or -1 if end of stream reached.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        /// <exception cref="LineSizeExceededException">Is raised when line is bigger than <b>buffer</b> can store.</exception>
        public virtual int ReadLine(byte[] buffer,int offset,int count,SizeExceededAction exceededAction,out int rawBytesReaded)
        {
            if(m_IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(buffer == null){
                throw new ArgumentNullException("buffer");
            }
            if(offset < 0){
                throw new ArgumentException("Argument 'offset' value must be >= 0.");
            }
            if(count < 0){
                throw new ArgumentException("Argument 'count' value must be >= 0.");
            }
            if(buffer.Length < (count + offset)){
                throw new ArgumentException("Argument 'count' value is bigger than specified 'buffer' can store.");
            }

            int  maxStoreCount  = buffer.Length - offset;
            int  storedCount    = 0;
                 rawBytesReaded = 0;
            bool sizeExceeded   = false;
            while(true){
                // No data in buffer, buffer next block.
                if(m_StoredInBuffer == m_OffsetInBuffer){                
                    m_OffsetInBuffer = 0;
                    m_StoredInBuffer = m_pSource.Read(m_pReadBuffer,0,m_BufferSize);
                    // We reached end of stream, no more data.
                    if(m_StoredInBuffer == 0){
                        break;
                    }
                }

                byte currentByte = m_pReadBuffer[m_OffsetInBuffer++];
                rawBytesReaded++;
                // We have LF, we got a line.
                if(currentByte == '\n'){
                    break;
                }
                // We just skip CR, because CR must be with LF, otherwise it's invalid CR.
                else if(currentByte == '\r'){
                }
                // Normal byte.
                else{
                    // Line buffer full.
                    if(storedCount == maxStoreCount){
                        sizeExceeded = true;

                        if(exceededAction == SizeExceededAction.ThrowException){
                            throw new LineSizeExceededException();
                        }
                    }
                    else{
                        buffer[offset + storedCount] = currentByte;
                        storedCount++;
                    }
                }
            }

            // Line buffer is not big enough to store whole line data.
            if(sizeExceeded){
                throw new LineSizeExceededException();
            }
            // We haven't readed nothing, we are end of stream.
            else if(rawBytesReaded == 0){
                return -1;
            }
            else{
                return storedCount;
            }
        }
开发者ID:iraychen,项目名称:ourmsg,代码行数:84,代码来源:LineReader.cs

示例14: ReadLineAsyncOperation

            /// <summary>
            /// Default constructor.
            /// </summary>
            /// <param name="owner">Owner stream.</param>
            /// <param name="buffer">Buffer where to store data.</param>
            /// <param name="offset">The location in <b>buffer</b> to begin storing the data.</param>
            /// <param name="maxCount">Maximum number of bytes to read.</param>
            /// <param name="exceededAction">Specifies how this method behaves when maximum line size exceeded.</param>
            /// <param name="callback">The AsyncCallback delegate that is executed when asynchronous operation completes.</param>
            /// <param name="asyncState">User-defined object that qualifies or contains information about an asynchronous operation.</param>
            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b>,<b>buffer</b> is null reference.</exception>
            /// <exception cref="ArgumentOutOfRangeException">Is raised when any of the arguments has out of valid range.</exception>
            public ReadLineAsyncOperation(SmartStream owner,
                                          byte[] buffer,
                                          int offset,
                                          int maxCount,
                                          SizeExceededAction exceededAction,
                                          AsyncCallback callback,
                                          object asyncState)
            {
                if (owner == null)
                {
                    throw new ArgumentNullException("owner");
                }
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer");
                }
                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset", "Argument 'offset' value must be >= 0.");
                }
                if (offset > buffer.Length)
                {
                    throw new ArgumentOutOfRangeException("offset",
                                                          "Argument 'offset' value must be < buffer.Length.");
                }
                if (maxCount < 0)
                {
                    throw new ArgumentOutOfRangeException("maxCount",
                                                          "Argument 'maxCount' value must be >= 0.");
                }
                if (offset + maxCount > buffer.Length)
                {
                    throw new ArgumentOutOfRangeException("maxCount",
                                                          "Argument 'maxCount' is bigger than than argument 'buffer' can store.");
                }

                m_pOwner = owner;
                m_pBuffer = buffer;
                m_OffsetInBuffer = offset;
                m_MaxCount = maxCount;
                m_SizeExceededAction = exceededAction;
                m_pAsyncCallback = callback;
                m_pAsyncState = asyncState;

                m_pAsyncWaitHandle = new AutoResetEvent(false);

                DoLineReading();
            }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:60,代码来源:SmartStream.cs

示例15: ReadPeriodTerminatedAsyncOP

            /// <summary>
            /// Default constructor.
            /// </summary>
            /// <param name="stream">Stream wehre to sore readed data.</param>
            /// <param name="maxCount">Maximum number of bytes to read. Value 0 means not limited.</param>
            /// <param name="exceededAction">Specifies how period-terminated reader behaves when <b>maxCount</b> exceeded.</param>
            /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null reference.</exception>
            public ReadPeriodTerminatedAsyncOP(Stream stream, long maxCount, SizeExceededAction exceededAction)
            {
                if (stream == null)
                {
                    throw new ArgumentNullException("stream");
                }

                m_pStream = stream;
                m_MaxCount = maxCount;
                m_ExceededAction = exceededAction;

                m_pReadLineOP = new ReadLineAsyncOP(new byte[Workaround.Definitions.MaxStreamLineLength], exceededAction);
                m_pReadLineOP.Completed += m_pReadLineOP_Completed;
            }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:21,代码来源:SmartStream.cs


注:本文中的SizeExceededAction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。