public override int Read(byte[] buffer, int offset, int count)
        {
            Stream inputStream;

            lock (OutputStreams)
            {
                if (OutputStreams.Count == 0)
                {
                    return(0);
                }
                inputStream = OutputStreams[0];
            }
            try
            {
                int bytesRead = inputStream.Read(buffer, offset, count);
                Trace.TraceInformation("Read() : {0} bytes read for {1}", count, RuntimeHelpers.GetHashCode(this));
                return(bytesRead);
            }
            catch (Exception e)
            {
                lock (OutputStreams)
                {
                    OutputStreams.Remove(inputStream);
                }
                throw e;
            }
        }
 public override void Write(byte[] buffer, int offset, int count)
 {
     lock (OutputStreams)
     {
         IsLastWriteSuccessful = true;
         if (count > 0 && IsRecordEnabled)
         {
             byte[] add = new byte[count];
             Buffer.BlockCopy(buffer, offset, add, 0, count);
             Trace.TraceInformation("Write() : add chunk for {0}", RuntimeHelpers.GetHashCode(this));
             internalBuffer.Add(add);
         }
         List <Stream> streamsBroken = new List <Stream>();
         foreach (var stream in OutputStreams)
         {
             try
             {
                 Trace.TraceInformation("Write() : write data for {0}", RuntimeHelpers.GetHashCode(this));
                 stream.Write(buffer, offset, count);
             }
             catch (IOException)
             {
                 IsLastWriteSuccessful = false;
                 streamsBroken.Add(stream);
             }
         }
         foreach (var stream in streamsBroken)
         {
             OutputStreams.Remove(stream);
             Trace.TraceInformation("AddStream() : Remove stream for {0}", RuntimeHelpers.GetHashCode(this));
         }
     }
 }