StreamUtil.cs 521 B

1234567891011121314151617181920
  1. using System;
  2. using System.Buffers;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace JsonRPC4.Router.Utilities
  9. {
  10. internal class StreamUtil
  11. {
  12. internal static MemoryStream GetStreamFromUtf8String(string utf8Text)
  13. {
  14. byte[] array = ArrayPool<byte>.Shared.Rent(Encoding.UTF8.GetByteCount(utf8Text));
  15. int bytes = Encoding.UTF8.GetBytes(utf8Text, 0, utf8Text.Length, array, 0);
  16. return new MemoryStream(array, 0, bytes);
  17. }
  18. }
  19. }