[profiler] Introduce the Mono.Profiler.Log library. API still unstable.
[mono.git] / mcs / class / Mono.Profiler.Log / Mono.Profiler.Log / LogStream.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using System;
6 using System.IO;
7
8 namespace Mono.Profiler.Log {
9
10         public class LogStream : Stream {
11
12                 public Stream BaseStream { get; }
13
14                 public virtual bool EndOfStream => BaseStream.Position == BaseStream.Length;
15
16                 public override bool CanRead => true;
17
18                 public override bool CanSeek => false;
19
20                 public override bool CanWrite => false;
21
22                 public override long Length => throw new NotSupportedException ();
23
24                 public override long Position {
25                         get => throw new NotSupportedException ();
26                         set => throw new NotSupportedException ();
27                 }
28
29                 public LogStream (Stream baseStream)
30                 {
31                         if (baseStream == null)
32                                 throw new ArgumentNullException (nameof (baseStream));
33
34                         if (!baseStream.CanRead)
35                                 throw new ArgumentException ("Stream does not support reading.", nameof (baseStream));
36
37                         BaseStream = baseStream;
38                 }
39
40                 protected override void Dispose (bool disposing)
41                 {
42                         if (disposing)
43                                 BaseStream.Dispose ();
44                 }
45
46                 public override void Flush ()
47                 {
48                         throw new NotSupportedException ();
49                 }
50
51                 public override int Read (byte[] buffer, int offset, int count)
52                 {
53                         return BaseStream.Read (buffer, offset, count);
54                 }
55
56                 public override long Seek (long offset, SeekOrigin origin)
57                 {
58                         throw new NotSupportedException ();
59                 }
60
61                 public override void SetLength (long value)
62                 {
63                         throw new NotSupportedException ();
64                 }
65
66                 public override void Write (byte[] buffer, int offset, int count)
67                 {
68                         throw new NotSupportedException ();
69                 }
70         }
71 }