Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Write() [2/2]

override void System.Text.TranscodingStream.Write ( ReadOnlySpan< byte > buffer)
inlinevirtual

Reimplemented from System.IO.Stream.

Definition at line 346 of file TranscodingStream.cs.

347 {
349 if (buffer.IsEmpty)
350 {
351 return;
352 }
353 int minimumLength = Math.Clamp(buffer.Length, 4096, 1048576);
354 char[] array = ArrayPool<char>.Shared.Rent(minimumLength);
355 byte[] array2 = ArrayPool<byte>.Shared.Rent(minimumLength);
356 try
357 {
358 bool completed;
359 do
360 {
361 _thisDecoder.Convert(buffer, array, flush: false, out var bytesUsed, out var charsUsed, out completed);
362 buffer = buffer.Slice(bytesUsed);
363 Span<char> span = array.AsSpan(0, charsUsed);
364 bool completed2;
365 do
366 {
367 _innerEncoder.Convert(span, array2, flush: false, out var charsUsed2, out var bytesUsed2, out completed2);
368 span = span.Slice(charsUsed2);
369 _innerStream.Write(array2, 0, bytesUsed2);
370 }
371 while (!completed2);
372 }
373 while (!completed);
374 }
375 finally
376 {
378 ArrayPool<byte>.Shared.Return(array2);
379 }
380 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
void Write(byte[] buffer, int offset, int count)
virtual void Convert(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
Definition Decoder.cs:142
virtual void Convert(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, int byteCount, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
Definition Encoder.cs:135

References System.Text.TranscodingStream._innerEncoder, System.Text.TranscodingStream._innerStream, System.Text.TranscodingStream._thisDecoder, System.array, System.buffer, System.Math.Clamp(), System.Text.Decoder.Convert(), System.Text.Encoder.Convert(), System.Text.TranscodingStream.EnsurePreWriteConditions(), System.Buffers.ArrayPool< T >.Shared, System.Span< T >.Slice(), and System.IO.Stream.Write().