StreamResourceUtility.cs 715 B

123456789101112131415161718192021222324252627
  1. using System.Linq;
  2. using System.Text;
  3. namespace NModbus.IO
  4. {
  5. internal static class StreamResourceUtility
  6. {
  7. internal static string ReadLine(IStreamResource stream)
  8. {
  9. var result = new StringBuilder();
  10. var singleByteBuffer = new byte[1];
  11. do
  12. {
  13. if (stream.Read(singleByteBuffer, 0, 1) == 0)
  14. {
  15. continue;
  16. }
  17. result.Append(Encoding.UTF8.GetChars(singleByteBuffer).First());
  18. }
  19. while (!result.ToString().EndsWith(Modbus.NewLine));
  20. return result.ToString().Substring(0, result.Length - Modbus.NewLine.Length);
  21. }
  22. }
  23. }