Advertisement
Guest User

Untitled

a guest
Sep 5th, 2022
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | Software | 0 0
  1. public class ConsoleInterceptedStream : Stream
  2. {
  3.     private readonly Stream stream;
  4.  
  5.     public override bool CanRead => this.stream.CanRead;
  6.     public override bool CanSeek => this.stream.CanSeek;
  7.     public override bool CanWrite => this.stream.CanWrite;
  8.     public override long Length => this.stream.Length;
  9.     public override long Position
  10.     {
  11.         get => this.stream.Position;
  12.         set => this.stream.Position = value;
  13.     }
  14.  
  15.     public ConsoleInterceptedStream(Stream stream)
  16.     {
  17.         this.stream = stream;
  18.  
  19.         Console.WriteLine($"CanRead: {stream.CanRead}");
  20.         Console.WriteLine($"CanSeek: {stream.CanSeek}");
  21.         Console.WriteLine($"CanWrite: {stream.CanWrite}");
  22.         Console.WriteLine($"Length: {stream.Length}");
  23.     }
  24.  
  25.     public override void Flush()
  26.     {
  27.         Console.WriteLine("Flushed");
  28.     }
  29.  
  30.     public override int Read(byte[] buffer, int offset, int count)
  31.     {
  32.         Console.WriteLine($"Read {offset} {count}");
  33.         return this.stream.Read(buffer, offset, count);
  34.     }
  35.  
  36.     public override long Seek(long offset, SeekOrigin origin)
  37.     {
  38.         Console.WriteLine($"Seek {offset} {origin}");
  39.         return this.stream.Seek(offset, origin);
  40.     }
  41.  
  42.     public override void SetLength(long value)
  43.     {
  44.         throw new NotImplementedException();
  45.     }
  46.  
  47.     public override void Write(byte[] buffer, int offset, int count)
  48.     {
  49.         throw new NotImplementedException();
  50.     }
  51.  
  52.     protected override void Dispose(bool disposing)
  53.     {
  54.         this.stream.Dispose();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement