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

◆ FlushAsyncInternal()

Task System.IO.StreamWriter.FlushAsyncInternal ( bool flushStream,
bool flushEncoder,
CancellationToken cancellationToken = default(CancellationToken) )
inlineprivate

Definition at line 786 of file StreamWriter.cs.

787 {
788 if (cancellationToken.IsCancellationRequested)
789 {
791 }
792 if (_charPos == 0 && !flushStream && !flushEncoder)
793 {
794 return Task.CompletedTask;
795 }
796 return Core(flushStream, flushEncoder, cancellationToken);
797 async Task Core(bool flushStream, bool flushEncoder, CancellationToken cancellationToken)
798 {
800 {
802 byte[] preamble = _encoding.GetPreamble();
803 if (preamble.Length != 0)
804 {
805 await _stream.WriteAsync(new ReadOnlyMemory<byte>(preamble), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
806 }
807 }
808 byte[] array = _byteBuffer ?? (_byteBuffer = new byte[_encoding.GetMaxByteCount(_charBuffer.Length)]);
809 int bytes = _encoder.GetBytes(new ReadOnlySpan<char>(_charBuffer, 0, _charPos), array, flushEncoder);
810 _charPos = 0;
811 if (bytes > 0)
812 {
813 await _stream.WriteAsync(new ReadOnlyMemory<byte>(array, 0, bytes), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
814 }
815 if (flushStream)
816 {
817 await _stream.FlushAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
818 }
819 }
820 }
readonly Stream _stream
readonly Encoder _encoder
readonly char[] _charBuffer
readonly Encoding _encoding
Task FlushAsync()
Definition Stream.cs:669
Task WriteAsync(byte[] buffer, int offset, int count)
Definition Stream.cs:914
int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush)
int GetMaxByteCount(int charCount)
virtual byte[] GetPreamble()
Definition Encoding.cs:689
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363
static Task CompletedTask
Definition Task.cs:1120

References System.IO.StreamWriter._byteBuffer, System.IO.StreamWriter._charBuffer, System.IO.StreamWriter._charPos, System.IO.StreamWriter._encoder, System.IO.StreamWriter._encoding, System.IO.StreamWriter._haveWrittenPreamble, System.IO.StreamWriter._stream, System.array, System.bytes, System.cancellationToken, System.Threading.Tasks.Task< TResult >.CompletedTask, System.Threading.Tasks.Task< TResult >.ConfigureAwait(), System.IO.Stream.FlushAsync(), System.Threading.Tasks.Task< TResult >.FromCanceled(), System.Text.Encoder.GetBytes(), System.Text.Encoding.GetMaxByteCount(), System.Text.Encoding.GetPreamble(), and System.IO.Stream.WriteAsync().

Referenced by System.IO.StreamWriter.FlushAsync(), System.IO.StreamWriter.WriteAsyncInternal(), and System.IO.StreamWriter.WriteAsyncInternal().