Exemple #1
0
        void WriteInternal(byte [] src, int offset, int count)
        {
            if (count > buf_size)
            {
                // shortcut for long writes
                MonoIOError error;

                FlushBuffer();

                if (CanSeek && !isExposed)
                {
                    MonoIO.Seek(safeHandle, buf_start, SeekOrigin.Begin, out error);
                    if (error != MonoIOError.ERROR_SUCCESS)
                    {
                        throw MonoIO.GetException(GetSecureFileName(name), error);
                    }
                }

                int wcount = count;

                while (wcount > 0)
                {
                    int n = MonoIO.Write(safeHandle, src, offset, wcount, out error);
                    if (error != MonoIOError.ERROR_SUCCESS)
                    {
                        throw MonoIO.GetException(GetSecureFileName(name), error);
                    }

                    wcount -= n;
                    offset += n;
                }
                buf_start += count;
            }
            else
            {
                int copied = 0;
                while (count > 0)
                {
                    int n = WriteSegment(src, offset + copied, count);
                    copied += n;
                    count  -= n;

                    if (count == 0)
                    {
                        break;
                    }

                    FlushBuffer();
                }
            }
        }
Exemple #2
0
        void FlushBuffer(Stream st)
        {
            if (buf_dirty)
            {
                MonoIOError error;

                if (CanSeek == true && safeHandle == null)
                {
                    MonoIO.Seek(handle, buf_start,
                                SeekOrigin.Begin,
                                out error);
                    if (error != MonoIOError.ERROR_SUCCESS)
                    {
                        // don't leak the path information for isolated storage
                        throw MonoIO.GetException(GetSecureFileName(name), error);
                    }
                }
                if (st == null)
                {
                    int wcount = buf_length;
                    int offset = 0;
                    while (wcount > 0)
                    {
                        int n = MonoIO.Write(handle, buf, 0, buf_length, out error);
                        if (error != MonoIOError.ERROR_SUCCESS)
                        {
                            // don't leak the path information for isolated storage
                            throw MonoIO.GetException(GetSecureFileName(name), error);
                        }
                        wcount -= n;
                        offset += n;
                    }
                }
                else
                {
                    st.Write(buf, 0, buf_length);
                }
            }

            buf_start += buf_offset;
            buf_offset = buf_length = 0;
            buf_dirty  = false;
        }
Exemple #3
0
        void WriteInternal(byte [] src, int offset, int count)
        {
            if (count > buf_size)
            {
                // shortcut for long writes
                MonoIOError error;

                FlushBuffer();

                MonoIO.Write(handle, src, offset, count, out error);
                if (error != MonoIOError.ERROR_SUCCESS)
                {
                    // don't leak the path information for isolated storage
                    throw MonoIO.GetException(GetSecureFileName(name), error);
                }

                buf_start += count;
            }
            else
            {
                int copied = 0;
                while (count > 0)
                {
                    int n = WriteSegment(src, offset + copied, count);
                    copied += n;
                    count  -= n;

                    if (count == 0)
                    {
                        break;
                    }

                    FlushBuffer();
                }
            }
        }