[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / System.IO.Compression / SharpCompress / Common / EntryStream.cs
1 using System;
2 using System.IO;
3
4 namespace SharpCompress.Common
5 {
6     internal class EntryStream : Stream
7     {
8         private Stream stream;
9         private bool completed;
10         private bool isDisposed;
11
12         internal EntryStream(Stream stream)
13         {
14             this.stream = stream;
15         }
16
17         /// <summary>
18         /// When reading a stream from OpenEntryStream, the stream must be completed so use this to finish reading the entire entry.
19         /// </summary>
20         public void SkipEntry()
21         {
22             var buffer = new byte[4096];
23             while (Read(buffer, 0, buffer.Length) > 0)
24             {
25             }
26             completed = true;
27         }
28
29         protected override void Dispose(bool disposing)
30         {
31             if (!completed)
32             {
33                 throw new InvalidOperationException(
34                     "EntryStream has not been fully consumed.  Read the entire stream or use SkipEntry.");
35             }
36             if (isDisposed)
37             {
38                 return;
39             }
40             isDisposed = true;
41             base.Dispose(disposing);
42             stream.Dispose();
43         }
44
45         public override bool CanRead
46         {
47             get { return true; }
48         }
49
50         public override bool CanSeek
51         {
52             get { return false; }
53         }
54
55         public override bool CanWrite
56         {
57             get { return false; }
58         }
59
60         public override void Flush()
61         {
62             throw new System.NotImplementedException();
63         }
64
65         public override long Length
66         {
67             get { throw new System.NotImplementedException(); }
68         }
69
70         public override long Position
71         {
72             get { throw new System.NotImplementedException(); }
73             set { throw new System.NotImplementedException(); }
74         }
75
76         public override int Read(byte[] buffer, int offset, int count)
77         {
78             int read = stream.Read(buffer, offset, count);
79             if (read <= 0)
80             {
81                 completed = true;
82             }
83             return read;
84         }
85
86         public override long Seek(long offset, SeekOrigin origin)
87         {
88             throw new System.NotImplementedException();
89         }
90
91         public override void SetLength(long value)
92         {
93             throw new System.NotImplementedException();
94         }
95
96         public override void Write(byte[] buffer, int offset, int count)
97         {
98             throw new System.NotImplementedException();
99         }
100     }
101 }