示例#1
0
        /// <summary>
        /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
        /// </summary>
        /// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.
        /// </param><param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.
        /// </param><param name="count">The number of bytes to be written to the current stream.
        /// </param><exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length.
        /// </exception><exception cref="T:System.ArgumentNullException"><paramref name="buffer"/> is null.
        /// </exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="count"/> is negative.
        /// </exception><exception cref="T:System.IO.IOException">An I/O error occurs. Also thrown if an attempt to write
        /// beyond the block size is made.
        /// </exception><exception cref="T:System.NotSupportedException">The stream does not support writing.
        /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
        /// </exception><filterpriority>1</filterpriority>
        public override void Write(byte[] buffer, int offset, int count)
        {
            ValidateReadWriteParams(buffer, offset, count);

            long remaining = ChunkSize - Position;

            if (count > remaining)
            {
                string msg = "Blocked attempt to write block of [{0}] bytes - write goes beyond the current chunk. Chunk size is [{1}], stream position is [{2}].";
                msg = String.Format(msg, count, ChunkSize, Position);
                throw new IOException(msg);
            }

            //do not read further than the chunk
            int bytesToWrite = (int)Math.Min(count, ChunkSize - Position);

            //if there is nothing to write, really, don't invoke the stream
            if (bytesToWrite == 0)
            {
                return;
            }

            //write data and advance position
            DecoratedStream.Write(buffer, offset, bytesToWrite);
            position += bytesToWrite;
        }
示例#2
0
    /// <summary>
    /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
    /// </summary>
    /// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream. 
    /// </param><param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream. 
    /// </param><param name="count">The number of bytes to be written to the current stream. 
    /// </param><exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length. 
    /// </exception><exception cref="T:System.ArgumentNullException"><paramref name="buffer"/> is null. 
    /// </exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="count"/> is negative. 
    /// </exception><exception cref="T:System.IO.IOException">An I/O error occurs. Also thrown if an attempt to write
    /// beyond the block size is made.
    /// </exception><exception cref="T:System.NotSupportedException">The stream does not support writing. 
    /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. 
    /// </exception><filterpriority>1</filterpriority>
    public override void Write(byte[] buffer, int offset, int count)
    {
      ValidateReadWriteParams(buffer, offset, count);

      long remaining = ChunkSize - Position;
      if(count > remaining)
      {
        string msg = "Blocked attempt to write block of {0} bytes - write goes beyond the current chunk. Chunk size is '{1}', stream position is {2}.";
        msg = String.Format(msg, count, ChunkSize, Position);
        throw new IOException(msg);
      }

      //do not read further than the chunk
      int bytesToWrite = (int)Math.Min(count, ChunkSize - Position);
      DecoratedStream.Write(buffer, offset, bytesToWrite);

      //advance position
      position += bytesToWrite;
    }
示例#3
0
 /// <summary>
 /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
 /// </summary>
 /// <param name="buffer">An array of bytes. This method copies <paramref name="count"/> bytes from <paramref name="buffer"/> to the current stream.
 /// </param><param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin copying bytes to the current stream.
 /// </param><param name="count">The number of bytes to be written to the current stream.
 /// </param><exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is greater than the buffer length.
 /// </exception><exception cref="T:System.ArgumentNullException"><paramref name="buffer"/> is null.
 /// </exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="offset"/> or <paramref name="count"/> is negative.
 /// </exception><exception cref="T:System.IO.IOException">An I/O error occurs. Also thrown if an attempt to write
 /// beyond the block size is made.
 /// </exception><exception cref="T:System.NotSupportedException">The stream does not support writing.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><filterpriority>1</filterpriority>
 public override void Write(byte[] buffer, int offset, int count)
 {
     DecoratedStream.Write(buffer, offset, count);
 }