예제 #1
0
        // Writes a sequence of bytes to the current stream and advances the
        // current position within this stream by the number of bytes written
        /// <summary>
        /// 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 count bytes from buffer to the current stream.</param>
        /// <param name="offset">The zero-based byte offset in 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>
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (TheIStream != null)
            {
                if (offset != 0)
                {
                    throw new NotSupportedException("Only a zero offset is supported.");
                }

                // Pass "null" for the last parameter since we don't use the value
                TheIStream.Write(buffer, count, IntPtr.Zero);
            }
            else
            {
                TheStream.Write(buffer, offset, count);
            }
        }
예제 #2
0
 /// <summary>
 /// Writes a specified number of bytes into the stream object
 ///starting at the current seek pointer.
 /// </summary>
 /// <param name="pv">The buffer that contains the data that is to be written to the stream.
 /// A valid buffer must be provided for this parameter even when cb is zero.</param>
 /// <param name="cb">The number of bytes of data to attempt to write into the stream. This value can be zero.</param>
 /// <param name="pcbWritten">
 /// A variable where this method writes the actual number of bytes written to the stream object.
 /// The caller can set this to IntPtr.Zero, in which case this method does not provide the actual number of bytes written.
 /// </param>
 /// <typeparam name="pcbWritten">Native UInt32</typeparam>
 /// <returns>
 /// The actual number of bytes written (<paramref name="pcbWritten"/>).
 /// </returns>
 ///<exception cref="ArgumentException">The sum of offset and count is larger than the buffer length.</exception>
 ///<exception cref="ArgumentNullException">buffer is a null reference.</exception>
 ///<exception cref="ArgumentOutOfRangeException">offset or count is negative.</exception>
 ///<exception cref="IOException">An I/O error occurs.</exception>
 ///<exception cref="NotSupportedException">The IO.Stream does not support reading.</exception>
 ///<exception cref="ObjectDisposedException">Methods were called after the stream was closed.</exception>
 public void Write(byte[] pv, int cb, IntPtr pcbWritten)
 {
     if (TheStream != null)
     {
         if (pcbWritten == IntPtr.Zero)
         {
             // User isn't interested in how many bytes were written
             TheStream.Write(pv, 0, cb);
         }
         else
         {
             var currentPosition = TheStream.Position;
             TheStream.Write(pv, 0, cb);
             Marshal.WriteInt32(pcbWritten, (int)(TheStream.Position - currentPosition));
         }
     }
     else
     {
         TheIStream.Write(pv, cb, pcbWritten);
     }
 }