Пример #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, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
    /// </summary>
    /// <returns>
    /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
    /// </returns>
    /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the current source. 
    /// </param><param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream. 
    /// </param><param name="count">The maximum number of bytes to be read from the current stream. 
    /// </param><exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is larger 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. 
    /// </exception><exception cref="T:System.NotSupportedException">The stream does not support reading. 
    /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. 
    /// </exception><filterpriority>1</filterpriority>
    public override int Read(byte[] buffer, int offset, int count)
    {
      ValidateReadWriteParams(buffer, offset, count);

      //do not read further than the chunk
      int bytesToRead = (int)Math.Min(count, ChunkSize - Position);
      int receivedBytes = DecoratedStream.Read(buffer, offset, bytesToRead);
      
      //update received bytes
      position += receivedBytes;

      return receivedBytes;
    }
Пример #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)
    {
      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;
    }
Пример #4
0
        /// <summary>
        /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
        /// </summary>
        /// <returns>
        /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
        /// </returns>
        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the current source.
        /// </param><param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream.
        /// </param><param name="count">The maximum number of bytes to be read from the current stream.
        /// </param><exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is larger 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.
        /// </exception><exception cref="T:System.NotSupportedException">The stream does not support reading.
        /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
        /// </exception><filterpriority>1</filterpriority>
        public override int Read(byte[] buffer, int offset, int count)
        {
            ValidateReadWriteParams(buffer, offset, count);

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

            //if we do not have anything to read, don't read at all - this closes underlying stream
            //implementations!!!
            if (bytesToRead == 0)
            {
                return(0);
            }

            int receivedBytes = DecoratedStream.Read(buffer, offset, bytesToRead);

            //update received bytes
            position += receivedBytes;

            return(receivedBytes);
        }
Пример #5
0
 /// <summary>
 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <returns>
 /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
 /// </returns>
 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.
 /// </param><exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.
 /// </exception><filterpriority>2</filterpriority>
 public override bool Equals(object obj)
 {
     return(DecoratedStream.Equals(obj));
 }
Пример #6
0
 /// <summary>
 /// Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
 /// </summary>
 /// <returns>
 /// The unsigned byte cast to an Int32, or -1 if at the end of the stream.
 /// </returns>
 /// <exception cref="T:System.NotSupportedException">The stream does not support reading.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><filterpriority>2</filterpriority>
 public override int ReadByte()
 {
     return(DecoratedStream.ReadByte());
 }
Пример #7
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override int GetHashCode()
 {
     return(DecoratedStream.GetHashCode());
 }
Пример #8
0
 /// <summary>
 /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override string ToString()
 {
     return(DecoratedStream.ToString());
 }
Пример #9
0
 /// <summary>
 /// Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
 /// </summary>
 /// <returns>
 /// Information required to generate a proxy.
 /// </returns>
 /// <param name="requestedType">The <see cref="T:System.Type"/> of the object that the new <see cref="T:System.Runtime.Remoting.ObjRef"/> will reference.
 /// </param><exception cref="T:System.Runtime.Remoting.RemotingException">This instance is not a valid remoting object.
 /// </exception><exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission.
 /// </exception><filterpriority>2</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure"/></PermissionSet>
 public override System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType)
 {
     return(DecoratedStream.CreateObjRef(requestedType));
 }
Пример #10
0
 /// <summary>
 /// Obtains a lifetime service object to control the lifetime policy for this instance.
 /// </summary>
 /// <returns>
 /// An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease"/> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime"/> property.
 /// </returns>
 /// <exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission.
 /// </exception><filterpriority>2</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="RemotingConfiguration, Infrastructure"/></PermissionSet>
 public override object InitializeLifetimeService()
 {
     return(DecoratedStream.InitializeLifetimeService());
 }
Пример #11
0
 /// <summary>
 /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
 /// </summary>
 /// <returns>
 /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
 /// </returns>
 /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the current source.
 /// </param><param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream.
 /// </param><param name="count">The maximum number of bytes to be read from the current stream.
 /// </param><exception cref="T:System.ArgumentException">The sum of <paramref name="offset"/> and <paramref name="count"/> is larger 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.
 /// </exception><exception cref="T:System.NotSupportedException">The stream does not support reading.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><filterpriority>1</filterpriority>
 public override int Read(byte[] buffer, int offset, int count)
 {
     return(DecoratedStream.Read(buffer, offset, count));
 }
Пример #12
0
 /// <summary>
 /// Writes a byte to the current position in the stream and advances the position within the stream by one byte.
 /// </summary>
 /// <param name="value">The byte to write to the stream.
 /// </param><exception cref="T:System.IO.IOException">An I/O error occurs.
 /// </exception><exception cref="T:System.NotSupportedException">The stream does not support writing, or the stream is already closed.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><filterpriority>2</filterpriority>
 public override void WriteByte(byte value)
 {
     DecoratedStream.WriteByte(value);
 }
Пример #13
0
 /// <summary>
 /// Waits for the pending asynchronous read to complete.
 /// </summary>
 /// <returns>
 /// The number of bytes read from the stream, between zero (0) and the number of bytes you requested. Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.
 /// </returns>
 /// <param name="asyncResult">The reference to the pending asynchronous request to finish.
 /// </param><exception cref="T:System.ArgumentNullException"><paramref name="asyncResult"/> is null.
 /// </exception><exception cref="T:System.ArgumentException"><paramref name="asyncResult"/> did not originate from a <see cref="M:System.IO.Stream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)"/> method on the current stream.
 /// </exception><exception cref="T:System.IO.IOException">The stream is closed or an internal error has occurred.
 /// </exception><filterpriority>2</filterpriority>
 public override int EndRead(IAsyncResult asyncResult)
 {
     return(DecoratedStream.EndRead(asyncResult));
 }
Пример #14
0
 public override void Flush()
 {
   DecoratedStream.Flush();
 }
Пример #15
0
 /// <summary>
 /// Begins an asynchronous write operation.
 /// </summary>
 /// <returns>
 /// An IAsyncResult that represents the asynchronous write, which could still be pending.
 /// </returns>
 /// <param name="buffer">The buffer to write data from.
 /// </param><param name="offset">The byte offset in <paramref name="buffer"/> from which to begin writing.
 /// </param><param name="count">The maximum number of bytes to write.
 /// </param><param name="callback">An optional asynchronous callback, to be called when the write is complete.
 /// </param><param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests.
 /// </param><exception cref="T:System.IO.IOException">Attempted an asynchronous write past the end of the stream, or a disk error occurs.
 /// </exception><exception cref="T:System.ArgumentException">One or more of the arguments is invalid.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><exception cref="T:System.NotSupportedException">The current Stream implementation does not support the write operation.
 /// </exception><filterpriority>2</filterpriority>
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     return(DecoratedStream.BeginWrite(buffer, offset, count, callback, state));
 }
Пример #16
0
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream"/> and optionally releases the managed resources.
 /// </summary>
 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.
 /// </param>
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     DecoratedStream.Dispose();
 }
Пример #17
0
 /// <summary>
 /// When overridden in a derived class, sets the length of the current stream.
 /// </summary>
 /// <param name="value">The desired length of the current stream in bytes.
 /// </param><exception cref="T:System.IO.IOException">An I/O error occurs.
 /// </exception><exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><filterpriority>2</filterpriority>
 public override void SetLength(long value)
 {
     DecoratedStream.SetLength(value);
 }
Пример #18
0
 /// <summary>
 /// When overridden in a derived class, sets the position within the current stream.
 /// </summary>
 /// <returns>
 /// The new position within the current stream.
 /// </returns>
 /// <param name="offset">A byte offset relative to the <paramref name="origin"/> parameter.
 /// </param><param name="origin">A value of type <see cref="T:System.IO.SeekOrigin"/> indicating the reference point used to obtain the new position.
 /// </param><exception cref="T:System.IO.IOException">An I/O error occurs.
 /// </exception><exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output.
 /// </exception><exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.
 /// </exception><filterpriority>1</filterpriority>
 public override long Seek(long offset, SeekOrigin origin)
 {
     return(DecoratedStream.Seek(offset, origin));
 }
Пример #19
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);
 }
Пример #20
0
 /// <summary>
 /// Ends an asynchronous write operation.
 /// </summary>
 /// <param name="asyncResult">A reference to the outstanding asynchronous I/O request.
 /// </param><exception cref="T:System.ArgumentNullException"><paramref name="asyncResult"/> is null.
 /// </exception><exception cref="T:System.ArgumentException"><paramref name="asyncResult"/> did not originate from a <see cref="M:System.IO.Stream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)"/> method on the current stream.
 /// </exception><exception cref="T:System.IO.IOException">The stream is closed or an internal error has occurred.
 /// </exception><filterpriority>2</filterpriority>
 public override void EndWrite(IAsyncResult asyncResult)
 {
     DecoratedStream.EndWrite(asyncResult);
 }
Пример #21
0
 /// <summary>
 /// Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
 /// </summary>
 /// <filterpriority>1</filterpriority>
 public override void Close()
 {
     DecoratedStream.Close();
     base.Close();
 }