Example #1
0
        internal FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool noBuffering)
        {
            this.handle = MonoIO.InvalidHandle;
            if (handle == this.handle)
            {
                throw new ArgumentException("handle", Locale.GetText("Invalid."));
            }

            if (access < FileAccess.Read || access > FileAccess.ReadWrite)
            {
                throw new ArgumentOutOfRangeException("access");
            }

            MonoIOError  error;
            MonoFileType ftype = MonoIO.GetFileType(handle, out error);

            if (error != MonoIOError.ERROR_SUCCESS)
            {
                throw MonoIO.GetException(name, error);
            }

            if (ftype == MonoFileType.Unknown)
            {
                throw new IOException("Invalid handle.");
            }
            else if (ftype == MonoFileType.Disk)
            {
                this.canseek = true;
            }
            else
            {
                this.canseek = false;
            }

            this.handle = handle;
            this.access = access;
            this.owner  = ownsHandle;
            this.async  = isAsync;
#if NET_2_1 && !MONOTOUCH
            // default the browser to 'all' anonymous files and let other usage (like smcs) with 'normal'
            // (i.e. non-anonymous except for isolated storage) files and paths
            this.anonymous = SecurityManager.SecurityEnabled;
#else
            this.anonymous = false;
#endif

            InitBuffer(bufferSize, noBuffering);

            if (canseek)
            {
                buf_start = MonoIO.Seek(handle, 0, SeekOrigin.Current, out error);
                if (error != MonoIOError.ERROR_SUCCESS)
                {
                    throw MonoIO.GetException(name, error);
                }
            }

            /* Can't set append mode */
            this.append_startpos = 0;
        }
Example #2
0
        private void Init(SafeFileHandle safeHandle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isConsoleWrapper)
        {
            if (!isConsoleWrapper && safeHandle.IsInvalid)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_InvalidHandle"), "handle");
            }
            if (access < FileAccess.Read || access > FileAccess.ReadWrite)
            {
                throw new ArgumentOutOfRangeException("access");
            }
            if (!isConsoleWrapper && bufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
            }

            MonoIOError  error;
            MonoFileType ftype = MonoIO.GetFileType(safeHandle, out error);

            if (error != MonoIOError.ERROR_SUCCESS)
            {
                throw MonoIO.GetException(name, error);
            }

            if (ftype == MonoFileType.Unknown)
            {
                throw new IOException("Invalid handle.");
            }
            else if (ftype == MonoFileType.Disk)
            {
                this.canseek = true;
            }
            else
            {
                this.canseek = false;
            }

            this.safeHandle = safeHandle;
            ExposeHandle();
            this.access    = access;
            this.owner     = ownsHandle;
            this.async     = isAsync;
            this.anonymous = false;

            if (canseek)
            {
                buf_start = MonoIO.Seek(safeHandle, 0, SeekOrigin.Current, out error);
                if (error != MonoIOError.ERROR_SUCCESS)
                {
                    throw MonoIO.GetException(name, error);
                }
            }

            /* Can't set append mode */
            this.append_startpos = 0;
        }
Example #3
0
        internal FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isZeroSize)
        {
            this.handle = MonoIO.InvalidHandle;
            if (handle == this.handle)
            {
                throw new ArgumentException("handle", Locale.GetText("Invalid."));
            }

            if (access < FileAccess.Read || access > FileAccess.ReadWrite)
            {
                throw new ArgumentOutOfRangeException("access");
            }

            MonoIOError  error;
            MonoFileType ftype = MonoIO.GetFileType(handle, out error);

            if (error != MonoIOError.ERROR_SUCCESS)
            {
                throw MonoIO.GetException(name, error);
            }

            if (ftype == MonoFileType.Unknown)
            {
                throw new IOException("Invalid handle.");
            }
            else if (ftype == MonoFileType.Disk)
            {
                this.canseek = true;
            }
            else
            {
                this.canseek = false;
            }

            this.handle = handle;
            ExposeHandle();
            this.access    = access;
            this.owner     = ownsHandle;
            this.async     = isAsync;
            this.anonymous = false;
            if (canseek)
            {
                buf_start = MonoIO.Seek(handle, 0, SeekOrigin.Current, out error);
                if (error != MonoIOError.ERROR_SUCCESS)
                {
                    throw MonoIO.GetException(name, error);
                }
            }

            /* Can't set append mode */
            this.append_startpos = 0;
        }