/// <summary>
        /// See .NET Framework SDK under System.IO.Stream
        /// </summary>
        /// <param name="buffer">Data buffer</param>
        /// <param name="offset">Buffer write start position</param>
        /// <param name="count">Number of bytes to write</param>
        public override void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposedStatus();

            PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);

            int written = 0; // CLR guys have deemed this uninteresting?

            if (0 == offset) // Zero offset is typical case
            {
                _safeIStream.Write(buffer, count, out written);
            }
            else // Non-zero offset
            {
                // Copy from indicated offset to zero-based temp buffer
                byte[] localBuffer = new byte[count];
                Array.Copy(buffer, offset, localBuffer, 0, count);
                _safeIStream.Write(localBuffer, count, out written);
            }

            if (count != written)
            {
                throw new IOException(
                          SR.Get(SRID.WriteFailure));
            }
        }
示例#2
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     this.CheckDisposed();
     PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);
     if (count != 0)
     {
         int num2 = 0;
         this._dirtyFlag   = true;
         this._dataChanged = true;
         long num = this._currentStreamPosition;
         if (num < this._persistedSize)
         {
             this._blockManager.Stream.Seek(this._persistedOffset + num, SeekOrigin.Begin);
             num2 = (int)Math.Min((long)count, this._persistedSize - num);
             this._blockManager.Stream.Write(buffer, offset, num2);
             num    += num2;
             count  -= num2;
             offset += num2;
         }
         if ((num + count) > this._persistedSize)
         {
             if (this._sparseMemoryStreamSuffix == null)
             {
                 this._sparseMemoryStreamSuffix = new SparseMemoryStream(0x19000L, 0xa00000L);
             }
             this._sparseMemoryStreamSuffix.Seek(num - this._persistedSize, SeekOrigin.Begin);
             this._sparseMemoryStreamSuffix.Write(buffer, offset, count);
             num += count;
         }
         this._currentStreamPosition = num;
         this._currentStreamLength   = Math.Max(this._currentStreamLength, this._currentStreamPosition);
     }
 }
示例#3
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            this.CheckDisposed();
            PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);
            if (count != 0)
            {
                switch (this._mode)
                {
                case Mode.Start:
                    if ((this._position != 0L) || !IsDeflateStreamEmpty(this._baseStream))
                    {
                        this.ChangeMode(Mode.Emulation);
                        break;
                    }
                    this.ChangeMode(Mode.WritePassThrough);
                    break;

                case Mode.ReadPassThrough:
                    this.ChangeMode(Mode.Emulation);
                    break;
                }
                this._current.Write(buffer, offset, count);
                this._position += count;
                if (this._mode == Mode.WritePassThrough)
                {
                    this.CachedLength = this._position;
                }
                this._dirtyForFlushing = true;
                this._dirtyForClosing  = true;
            }
        }
示例#4
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     this.CheckDisposed();
     PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);
     if (count != 0)
     {
         if (this._isolatedStorageMode)
         {
             this._isolatedStorageStream.Seek(this._currentStreamPosition, SeekOrigin.Begin);
             this._isolatedStorageStream.Write(buffer, offset, count);
             this._currentStreamPosition += count;
         }
         else
         {
             this.WriteAndCollapseBlocks(buffer, offset, count);
         }
         this._currentStreamLength = Math.Max(this._currentStreamLength, this._currentStreamPosition);
         this.SwitchModeIfNecessary();
     }
 }
示例#5
0
        /// <summary>
        /// See .NET Framework SDK under System.IO.Stream
        /// </summary>
        public override void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);

            _writeCache.Seek(this.Position, SeekOrigin.Begin);

            _writeCache.Write(buffer, offset, count);

            // we also might need to recalculate the size of the new updated stream
            if (_writeCache.Length > Length)
            {
                // update our size accordingly
                SetLength(_writeCache.Length);
            }

            checked { _streamPosition += count; }

            FlushCacheIfNecessary();
        }
示例#6
0
        /// <summary>
        /// Write
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <remarks>In streaming mode, write should accumulate data into the SparseMemoryStream.</remarks>
        override public void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            PackagingUtilities.VerifyStreamWriteArgs(this, buffer, offset, count);

            Debug.Assert(_cachePrefixStream == null); // we only expect this thing to be not null during Archive Save execution
                                                      // that would between PreSaveNotofication call and Save SaveStreaming

            Debug.Assert(_currentStreamPosition >= 0);

            if (count == 0)
            {
                return;
            }

            int diskBytesToWrite = 0;

            _dirtyFlag   = true;
            _dataChanged = true;
            long newStreamPosition = _currentStreamPosition;

            checked
            {
                // Try to satisfy request with the Write to the Disk
                if (newStreamPosition < _persistedSize)
                {
                    Debug.Assert(!_blockManager.Streaming);

                    // we have at least partial overlap between request and the data on disk
                    _blockManager.Stream.Seek(_persistedOffset + newStreamPosition, SeekOrigin.Begin);
                    // Note on casting:
                    //  It is safe to cast the result of Math.Min(count, _persistedSize - newStreamPosition))
                    //      from long to int since it cannot be bigger than count and count is int type
                    diskBytesToWrite = (int)(Math.Min(count, _persistedSize - newStreamPosition));   // this is a safe cast as count has int type

                    _blockManager.Stream.Write(buffer, offset, diskBytesToWrite);
                    newStreamPosition += diskBytesToWrite;
                    count             -= diskBytesToWrite;
                    offset            += diskBytesToWrite;
                }

                // check whether we need to save data to the memory Stream;
                if (newStreamPosition + count > _persistedSize)
                {
                    if (_sparseMemoryStreamSuffix == null)
                    {
                        _sparseMemoryStreamSuffix = new SparseMemoryStream(_lowWaterMark, _highWaterMark);
                    }

                    _sparseMemoryStreamSuffix.Seek(newStreamPosition - _persistedSize, SeekOrigin.Begin);

                    _sparseMemoryStreamSuffix.Write(buffer, offset, count);
                    newStreamPosition += count;
                }

                _currentStreamPosition = newStreamPosition;
                _currentStreamLength   = Math.Max(_currentStreamLength, _currentStreamPosition);
            }
            return;
        }