IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
EncodingByteBufferWriter.cs
Go to the documentation of this file.
1using System;
2using System.Buffers;
3using System.Text;
4
6{
7
12 where TWriter : IBufferWriter<byte>
13 {
14
15 readonly Encoding _encoding;
16 TWriter _buffer;
19
25 public EncodingByteBufferWriter(Encoding encoding, ref TWriter buffer)
26 {
27 _encoding = encoding ?? throw new ArgumentNullException(nameof(encoding));
28 _buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
29 }
30
34 public readonly int BytesWritten => _bytesWritten;
35
39 public readonly int CharsWritten => _charsWritten;
40
45 public void Write(string text)
46 {
47 var l = _encoding.GetByteCount(text);
48 var b = _buffer.GetSpan(l);
50 _buffer.Advance(l);
51 _bytesWritten += l;
52 _charsWritten += text.Length;
53 }
54
59 public void Write(ReadOnlySpan<char> text)
60 {
61 var l = _encoding.GetByteCount(text);
62 var b = _buffer.GetSpan(l);
64 _buffer.Advance(l);
65 _bytesWritten += l;
66 _charsWritten += text.Length;
67 }
68
72 public void WriteLine()
73 {
74 Write(Environment.NewLine);
75 }
76
77 }
78
79}
Provides an interface to write text to a IBufferWriter<byte>.
void Write(ReadOnlySpan< char > text)
Writes the text to the span, advancing the current position.
void Write(string text)
Writes the text to the span, advancing the current position.
void WriteLine()
Writes a line feed to the span.
readonly int CharsWritten
Gets the number of characters written.
EncodingByteBufferWriter(Encoding encoding, ref TWriter buffer)
Initializes a new instance.
readonly int BytesWritten
Gets the number of bytes written.
Provides an interface to write text to a Span<byte>.
void Write(string text)
Writes the text to the span, advancing the current position.