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

◆ ReadToEndAsync()

static async ValueTask< ArraySegment< byte > > System.Text.Json.JsonDocument.ReadToEndAsync ( Stream stream,
CancellationToken cancellationToken )
inlinestaticprivate

Definition at line 1520 of file JsonDocument.cs.

1521 {
1522 int written = 0;
1523 byte[] rented = null;
1524 try
1525 {
1526 int utf8BomLength = JsonConstants.Utf8Bom.Length;
1527 if (stream.CanSeek)
1528 {
1529 long num = Math.Max(utf8BomLength, stream.Length - stream.Position) + 1;
1530 rented = ArrayPool<byte>.Shared.Rent(checked((int)num));
1531 }
1532 else
1533 {
1534 rented = ArrayPool<byte>.Shared.Rent(4096);
1535 }
1536 int num2;
1537 do
1538 {
1540 written += num2;
1541 }
1542 while (num2 > 0 && written < utf8BomLength);
1543 if (written == utf8BomLength && JsonConstants.Utf8Bom.SequenceEqual(rented.AsSpan(0, utf8BomLength)))
1544 {
1545 written = 0;
1546 }
1547 do
1548 {
1549 if (rented.Length == written)
1550 {
1551 byte[] array = rented;
1552 rented = ArrayPool<byte>.Shared.Rent(array.Length * 2);
1553 Buffer.BlockCopy(array, 0, rented, 0, array.Length);
1555 }
1556 num2 = await stream.ReadAsync(rented.AsMemory(written), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
1557 written += num2;
1558 }
1559 while (num2 > 0);
1560 return new ArraySegment<byte>(rented, 0, written);
1561 }
1562 catch
1563 {
1564 if (rented != null)
1565 {
1566 rented.AsSpan(0, written).Clear();
1568 }
1569 throw;
1570 }
1571 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7

References System.array, System.Buffer.BlockCopy(), System.cancellationToken, System.Text.Json.Dictionary, System.Math.Max(), System.Buffers.ArrayPool< T >.Shared, System.stream, and System.Text.Json.JsonConstants.Utf8Bom.

Referenced by System.Text.Json.JsonDocument.ParseAsyncCore().