Delete StreamString.cs

This commit is contained in:
Kurosh Dabbagh Escalante
2020-02-02 20:02:03 +01:00
committed by GitHub
parent d3a2b4f7e8
commit 5a8c241b74
-47
View File
@@ -1,47 +0,0 @@
using System;
using System.IO;
using System.Text;
namespace LOLBITS.TokenManagement
{
/// <summary>
/// Defines the data protocol for reading and writing strings on our stream.
/// </summary>
public class StreamString
{
private readonly Stream ioStream;
private readonly UnicodeEncoding streamEncoding;
public StreamString(Stream ioStream)
{
this.ioStream = ioStream;
streamEncoding = new UnicodeEncoding();
}
public string ReadString()
{
var len = ioStream.ReadByte() * 256;
len += ioStream.ReadByte();
var inBuffer = new byte[len];
ioStream.Read(inBuffer, 0, len);
return streamEncoding.GetString(inBuffer);
}
public int WriteString(string outString)
{
var outBuffer = streamEncoding.GetBytes(outString);
var len = outBuffer.Length;
if (len > ushort.MaxValue)
len = ushort.MaxValue;
ioStream.WriteByte((byte)(len / 256));
ioStream.WriteByte((byte)(len & 255));
ioStream.Write(outBuffer, 0, len);
ioStream.Flush();
return outBuffer.Length + 2;
}
}
}