Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProxyStream" /> class.
        /// </summary>
        /// <param name="underlyingStream">The underlying stream.</param>
        /// <param name="disposeUnderlyingStream">A value indicating whether to dispose the underlying stream.</param>
        /// <param name="options">The proxy stream options.</param>
        /// <param name="bufferSize">Size of the buffer.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">The buffer size is less than 1.</exception>
        /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
        /// <exception cref="System.NotSupportedException">The stream does not support reading and writing.</exception>
        public ProxyStream(Stream underlyingStream, Boolean disposeUnderlyingStream, ProxyStreamOptions options, Int32 bufferSize)
        {
            if (underlyingStream == null)
            {
                throw new ArgumentNullException("stream", "The stream is null.");
            }

            if (!underlyingStream.CanRead && !underlyingStream.CanWrite)
            {
                throw new NotSupportedException("The stream does not support reading and writing.");
            }

            if (bufferSize < 1)
            {
                throw new ArgumentOutOfRangeException("bufferSize", "The buffer size is less than 1.");
            }

            _baseStream        = underlyingStream;
            _isSingleAccess    = options.HasFlag(ProxyStreamOptions.SingleAccess);
            _isProxyModeForced = options.HasFlag(ProxyStreamOptions.ForceProxy);
            _bufferSize        = bufferSize;

            if (_baseStream.CanWrite && !_baseStream.CanRead)
            {
                InitializeStream(StreamAccessType.Writable);
            }
            else if (!_baseStream.CanWrite && _baseStream.CanRead)
            {
                InitializeStream(StreamAccessType.Readable);
            }

            _disposed          = false;
            _disposeBaseStream = disposeUnderlyingStream;

            EmptyBuffer = new Byte[_bufferSize];
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProxyStream" /> class.
 /// </summary>
 /// <param name="underlyingStream">The underlying stream.</param>
 /// <param name="disposeUnderlyingStream">A value indicating whether to dispose the underlying stream.</param>
 /// <param name="options">The proxy stream options.</param>
 /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
 /// <exception cref="System.NotSupportedException">The stream does not support reading and writing.</exception>
 public ProxyStream(Stream stream, Boolean disposeStream, ProxyStreamOptions options)
     : this(stream, disposeStream, options, DefaultBufferSize)
 {
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProxyStream" /> class.
 /// </summary>
 /// <param name="underlyingStream">The underlying stream.</param>
 /// <param name="options">The proxy stream options.</param>
 /// <exception cref="System.ArgumentNullException">The stream is null.</exception>
 /// <exception cref="System.NotSupportedException">The stream does not support reading and writing.</exception>
 public ProxyStream(Stream stream, ProxyStreamOptions options)
     : this(stream, false, options, DefaultBufferSize)
 {
 }