6
public class OutputStream : IDisposable
8
protected Stream Wrapped;
10
public static implicit operator OutputStream (Stream s)
15
public static implicit operator Stream (OutputStream s)
17
return s.GetWrappedStream ();
20
public virtual void Close ()
22
if (this.Wrapped != null) {
23
this.Wrapped.Close ();
27
public void Dispose ()
32
public virtual void Flush ()
34
if (this.Wrapped != null) {
35
this.Wrapped.Flush ();
39
internal Stream GetWrappedStream ()
41
// Always create a wrapper stream (not directly Wrapped) since the subclass
42
// may be overriding methods that need to be called when used through the Stream class
43
return new WrappedSystemStream (this);
46
static internal OutputStream Wrap (Stream s)
48
OutputStream stream = new OutputStream ();
53
public virtual void Write (int b)
55
if (Wrapped is WrappedSystemStream)
56
((WrappedSystemStream)Wrapped).OutputStream.Write (b);
58
if (this.Wrapped == null)
59
throw new NotImplementedException ();
60
this.Wrapped.WriteByte ((byte)b);
64
public virtual void Write (byte[] b)
66
this.Write (b, 0, b.Length);
69
public virtual void Write (byte[] b, int offset, int len)
71
if (Wrapped is WrappedSystemStream)
72
((WrappedSystemStream)Wrapped).OutputStream.Write (b, offset, len);
74
if (this.Wrapped != null) {
75
this.Wrapped.Write (b, offset, len);
77
for (int i = 0; i < len; i++) {
78
this.Write (b[i + offset]);