Пример #1
0
 /// <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];
 }
        /// <summary>
        /// Begins reading 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 data.</param>
        /// <param name="maxSize">Maximum muber of bytes to read.</param>
        /// <param name="exceededAction">Specifies how this method behaves when maximum size exceeded.</param>
        /// <param name="callback">Callback to be called if asynchronous reading completes.</param>
        /// <param name="tag">User data.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>storeStream</b> is null.</exception>
        /// <exception cref="InvalidOperationException">Raised when there already is pending read operation.</exception>
        public void BeginReadPeriodTerminated(Stream storeStream,int maxSize,SizeExceededAction exceededAction,ReadToStreamCallback callback,object tag)
        {
            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 !");
                }
                m_IsReadActive = false;
            }

            _ToStreamReader reader = new _ToStreamReader(this,storeStream,maxSize,exceededAction,callback,tag);
            reader.BeginReadPeriodTerminated();
        }
        /// <summary>
        /// Starts reading specified amount data and storing to the specified store stream.
        /// </summary>
        /// <param name="storeStream">Stream where to store readed data.</param>
        /// <param name="count">Number of bytes to read from source stream and write to store stream.</param>
        /// <param name="callback">Callback to be called if asynchronous reading completes.</param>
        /// <param name="tag">User data.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>storeStream</b> is null.</exception>
        /// <exception cref="ArgumentException">Raised when <b>count</b> less than 1.</exception>
        public void BeginRead(Stream storeStream,int count,ReadToStreamCallback callback,object tag)
        {
            if(storeStream == null){
                throw new ArgumentNullException("storeStream");
            }
            if(count < 1){
                throw new ArgumentException("Parameter count value must be >= 1 !");
            }
            lock(this){
                if(m_IsReadActive){
                    throw new InvalidOperationException("There is pending read operation, multiple read operations not allowed !");
                }
                m_IsReadActive = true;
            }

            _ToStreamReader reader = new _ToStreamReader(this,storeStream,0,SizeExceededAction.ThrowException,callback,tag);
            reader.BeginRead(count);
        }
Пример #4
0
 /// <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];
 }