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

◆ ReadToEnd()

static ArraySegment< byte > System.Text.Json.JsonDocument.ReadToEnd ( Stream stream)
inlinestaticprivate

Definition at line 1467 of file JsonDocument.cs.

1468 {
1469 int num = 0;
1470 byte[] array = null;
1471 ReadOnlySpan<byte> utf8Bom = JsonConstants.Utf8Bom;
1472 try
1473 {
1474 if (stream.CanSeek)
1475 {
1476 long num2 = Math.Max(utf8Bom.Length, stream.Length - stream.Position) + 1;
1477 array = ArrayPool<byte>.Shared.Rent(checked((int)num2));
1478 }
1479 else
1480 {
1481 array = ArrayPool<byte>.Shared.Rent(4096);
1482 }
1483 int num3;
1484 do
1485 {
1486 num3 = stream.Read(array, num, utf8Bom.Length - num);
1487 num += num3;
1488 }
1489 while (num3 > 0 && num < utf8Bom.Length);
1490 if (num == utf8Bom.Length && utf8Bom.SequenceEqual(array.AsSpan(0, utf8Bom.Length)))
1491 {
1492 num = 0;
1493 }
1494 do
1495 {
1496 if (array.Length == num)
1497 {
1498 byte[] array2 = array;
1499 array = ArrayPool<byte>.Shared.Rent(checked(array2.Length * 2));
1500 Buffer.BlockCopy(array2, 0, array, 0, array2.Length);
1502 }
1503 num3 = stream.Read(array, num, array.Length - num);
1504 num += num3;
1505 }
1506 while (num3 > 0);
1507 return new ArraySegment<byte>(array, 0, num);
1508 }
1509 catch
1510 {
1511 if (array != null)
1512 {
1513 array.AsSpan(0, num).Clear();
1515 }
1516 throw;
1517 }
1518 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7

References System.array, System.Buffer.BlockCopy(), 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.Parse(), and System.Text.Json.JsonDocument.ParseValue().