Example #1
0
        public FileStream(IntPtr handle, FileAccess access,
                          bool ownsHandle, int bufferSize,
                          bool isAsync)
        {
            // Validate the parameters.
            if (bufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException
                          ("bufferSize", _("ArgRange_BufferSize"));
            }
            if (access < FileAccess.Read ||
                access > FileAccess.ReadWrite)
            {
                throw new ArgumentOutOfRangeException
                          ("access", _("IO_FileAccess"));
            }
                        #if false
            if (!FileMethods.CheckHandleAccess(handle, access))
            {
                throw new UnauthorizedAccessException
                          (_("IO_IncorrectAccess"));
            }
                        #endif

            // Initialize the object state.
            this.handle             = handle;
            this.access             = access;
            this.ownsHandle         = ownsHandle;
            this.isAsync            = isAsync;
            this.bufferSize         = bufferSize;
            this.buffer             = new byte [bufferSize];
            this.bufferPosn         = 0;
            this.bufferLen          = 0;
            this.bufferOwnedByWrite = false;
            this.canSeek            = FileMethods.CanSeek(handle);
            if (canSeek)
            {
                this.position = FileMethods.Seek
                                    (handle, 0, SeekOrigin.Current);
            }
            else
            {
                this.position = 0;
            }
        }