71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
// /**
|
|
// * 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;
|
|
int _ch = 0;
|
|
|
|
while ((_ch = Stream.ReadByte()) != -1)
|
|
{
|
|
ch = (char)_ch;
|
|
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();
|
|
}
|
|
}
|
|
}
|