// /** // * File: UnbufferedStreamreader.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using System.IO; using System.Text; namespace ln.http.io { public class UnbufferedStreamReader : TextReader { public Stream Stream { get; } public UnbufferedStreamReader(Stream stream) { Stream = stream; } public override int Read() => Stream.ReadByte(); public override string ReadLine() { StringBuilder stringBuilder = new StringBuilder(); char ch; while ((ch = (char)Stream.ReadByte()) != -1) { if (ch == '\r') { ch = (char)Stream.ReadByte(); if (ch == '\n') return stringBuilder.ToString(); stringBuilder.Append('\r'); } stringBuilder.Append(ch); } if ((ch == -1) && (stringBuilder.Length == 0)) return null; return stringBuilder.ToString(); } public string ReadToken() { StringBuilder stringBuilder = new StringBuilder(); char ch = (char)Stream.ReadByte(); while (char.IsWhiteSpace(ch)) ch = (char)Stream.ReadByte(); while (!char.IsWhiteSpace(ch)) { stringBuilder.Append(ch); ch = (char)Stream.ReadByte(); } return stringBuilder.ToString(); } } }