IKVM11
11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
StreamDiagnosticChannel.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.IO;
3
using
System.IO.Pipelines;
4
using
System.Text
;
5
6
namespace
IKVM.Tools.Core.Diagnostics
7
{
8
12
class
StreamDiagnosticChannel
:
IDiagnosticChannel
, IDisposable
13
{
14
15
readonly Stream _stream;
16
readonly PipeWriter _pipe;
17
readonly
AsyncDiagnosticChannelWriter
_writer;
18
readonly Encoding _encoding;
19
26
public
StreamDiagnosticChannel
(Stream stream, Encoding encoding,
bool
leaveOpen =
true
)
27
{
28
_stream = stream ??
throw
new
ArgumentNullException(nameof(stream));
29
_pipe = PipeWriter.Create(_stream,
new
StreamPipeWriterOptions(leaveOpen: leaveOpen));
30
_writer =
new
AsyncDiagnosticChannelWriter
(_pipe);
31
_encoding = encoding ??
throw
new
ArgumentNullException(nameof(encoding));
32
}
33
35
public
IDiagnosticChannelWriter
Writer
=> _writer;
36
38
public
Encoding Encoding => _encoding;
39
43
public
void
Dispose
()
44
{
45
// dispose the writer, which causes the background writer to terminate and releases any buffers, but does not close the pipe
46
_writer.Dispose();
47
48
// flush and close the pipe, which should close the stream if requested
49
_pipe.FlushAsync().AsTask().GetAwaiter().GetResult();
50
_pipe.Complete();
51
}
52
53
}
54
55
}
IKVM.Tools.Core.Diagnostics.AsyncDiagnosticChannelWriter
Wraps a IBufferWriter<T> and queues data writen to it. Requires disposal to ensure flushing.
Definition
AsyncDiagnosticChannelWriter.cs:14
IKVM.Tools.Core.Diagnostics.StreamDiagnosticChannel
Implementation of IDiagnosticChannel that writes encoded text to a PipeWriter.
Definition
StreamDiagnosticChannel.cs:13
IKVM.Tools.Core.Diagnostics.StreamDiagnosticChannel.Writer
IDiagnosticChannelWriter Writer
Gets the writer that allows you to enqueue data to the channel.
Definition
StreamDiagnosticChannel.cs:35
IKVM.Tools.Core.Diagnostics.StreamDiagnosticChannel.StreamDiagnosticChannel
StreamDiagnosticChannel(Stream stream, Encoding encoding, bool leaveOpen=true)
Initializes a new instance.
Definition
StreamDiagnosticChannel.cs:26
IKVM.Tools.Core.Diagnostics.StreamDiagnosticChannel.Dispose
void Dispose()
Disposes of the instance.
Definition
StreamDiagnosticChannel.cs:43
IKVM.Tools.Core.Diagnostics.IDiagnosticChannelWriter
Definition
IDiagnosticChannelWriter.cs:8
IKVM.Tools.Core.Diagnostics.IDiagnosticChannel
Handles consuming and outputting diagnostic events.
Definition
IDiagnosticChannel.cs:10
IKVM.Tools.Core.Diagnostics
Definition
AsyncDiagnosticChannelWriter.cs:8
System.Text
Definition
EncodingExtensions.cs:5
System
Definition
HexConverter.cs:9
src
IKVM.Tools.Core
Diagnostics
StreamDiagnosticChannel.cs
Generated by
1.12.0