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.
8 namespace Mono.Profiler.Log {
10 public class LogStream : Stream {
12 public Stream BaseStream { get; }
14 public virtual bool EndOfStream => BaseStream.Position == BaseStream.Length;
16 public override bool CanRead => true;
18 public override bool CanSeek => false;
20 public override bool CanWrite => false;
22 public override long Length => throw new NotSupportedException ();
24 public override long Position {
25 get => throw new NotSupportedException ();
26 set => throw new NotSupportedException ();
29 readonly byte[] _byteBuffer = new byte [1];
31 public LogStream (Stream baseStream)
33 if (baseStream == null)
34 throw new ArgumentNullException (nameof (baseStream));
36 if (!baseStream.CanRead)
37 throw new ArgumentException ("Stream does not support reading.", nameof (baseStream));
39 BaseStream = baseStream;
42 protected override void Dispose (bool disposing)
45 BaseStream.Dispose ();
48 public override void Flush ()
50 throw new NotSupportedException ();
53 public override int ReadByte ()
55 // The base method on Stream is extremely inefficient in that it
56 // allocates a 1-byte array for every call. Simply use a private
58 return Read (_byteBuffer, 0, sizeof (byte)) == 0 ? -1 : _byteBuffer [0];
61 public override int Read (byte[] buffer, int offset, int count)
63 return BaseStream.Read (buffer, offset, count);
66 public override long Seek (long offset, SeekOrigin origin)
68 throw new NotSupportedException ();
71 public override void SetLength (long value)
73 throw new NotSupportedException ();
76 public override void Write (byte[] buffer, int offset, int count)
78 throw new NotSupportedException ();