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

◆ ReadAsyncInternal()

override async ValueTask< int > System.IO.StreamReader.ReadAsyncInternal ( Memory< char > buffer,
CancellationToken cancellationToken )
inlinepackagevirtualinherited

Reimplemented from System.IO.TextReader.

Definition at line 841 of file StreamReader.cs.

842 {
843 bool flag = _charPos == _charLen;
844 bool flag2 = flag;
845 if (flag2)
846 {
847 flag2 = await ReadBufferAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false) == 0;
848 }
849 if (flag2)
850 {
851 return 0;
852 }
853 int charsRead = 0;
854 bool readToUserBuffer = false;
855 byte[] tmpByteBuffer = _byteBuffer;
856 Stream tmpStream = _stream;
857 int count = buffer.Length;
858 while (count > 0)
859 {
860 int i = _charLen - _charPos;
861 if (i == 0)
862 {
863 _charLen = 0;
864 _charPos = 0;
865 if (!_checkPreamble)
866 {
867 _byteLen = 0;
868 }
869 readToUserBuffer = count >= _maxCharsPerBuffer;
870 do
871 {
872 if (_checkPreamble)
873 {
874 int bytePos = _bytePos;
875 int num = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer, bytePos, tmpByteBuffer.Length - bytePos), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
876 if (num == 0)
877 {
878 if (_byteLen > 0)
879 {
880 if (readToUserBuffer)
881 {
882 i = _decoder.GetChars(new ReadOnlySpan<byte>(tmpByteBuffer, 0, _byteLen), buffer.Span.Slice(charsRead), flush: false);
883 _charLen = 0;
884 }
885 else
886 {
887 i = _decoder.GetChars(tmpByteBuffer, 0, _byteLen, _charBuffer, 0);
888 _charLen += i;
889 }
890 }
891 _isBlocked = true;
892 break;
893 }
894 _byteLen += num;
895 }
896 else
897 {
898 _byteLen = await tmpStream.ReadAsync(new Memory<byte>(tmpByteBuffer), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
899 if (_byteLen == 0)
900 {
901 _isBlocked = true;
902 break;
903 }
904 }
905 _isBlocked = _byteLen < tmpByteBuffer.Length;
906 if (!IsPreamble())
907 {
908 if (_detectEncoding && _byteLen >= 2)
909 {
911 readToUserBuffer = count >= _maxCharsPerBuffer;
912 }
913 _charPos = 0;
914 if (readToUserBuffer)
915 {
916 i += _decoder.GetChars(new ReadOnlySpan<byte>(tmpByteBuffer, 0, _byteLen), buffer.Span.Slice(charsRead), flush: false);
917 _charLen = 0;
918 }
919 else
920 {
921 i = _decoder.GetChars(tmpByteBuffer, 0, _byteLen, _charBuffer, 0);
922 _charLen += i;
923 }
924 }
925 }
926 while (i == 0);
927 if (i == 0)
928 {
929 break;
930 }
931 }
932 if (i > count)
933 {
934 i = count;
935 }
936 if (!readToUserBuffer)
937 {
938 new Span<char>(_charBuffer, _charPos, i).CopyTo(buffer.Span.Slice(charsRead));
939 _charPos += i;
940 }
941 charsRead += i;
942 count -= i;
943 if (_isBlocked)
944 {
945 break;
946 }
947 }
948 return charsRead;
949 }
async ValueTask< int > ReadBufferAsync(CancellationToken cancellationToken)
readonly Stream _stream
readonly byte[] _byteBuffer
int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
Definition ValueTask.cs:312

References System.IO.StreamReader._byteBuffer, System.IO.StreamReader._byteLen, System.IO.StreamReader._bytePos, System.IO.StreamReader._charBuffer, System.IO.StreamReader._charLen, System.IO.StreamReader._charPos, System.IO.StreamReader._checkPreamble, System.IO.StreamReader._decoder, System.IO.StreamReader._detectEncoding, System.IO.StreamReader._isBlocked, System.IO.StreamReader._maxCharsPerBuffer, System.IO.StreamReader._stream, System.buffer, System.cancellationToken, System.Threading.Tasks.ValueTask< TResult >.ConfigureAwait(), System.Span< T >.CopyTo(), System.count, System.IO.StreamReader.DetectEncoding(), System.Text.Decoder.GetChars(), System.IO.StreamReader.IsPreamble(), System.IO.Stream.Length, System.IO.Stream.ReadAsync(), System.IO.StreamReader.ReadBufferAsync(), and System.ReadOnlySpan< T >.Slice().

Referenced by System.IO.StreamReader.ReadAsync(), and System.IO.StreamReader.ReadAsync().