forked from zeromq/clrzmq4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StreamReaderNoClose.cs
87 lines (74 loc) · 2.59 KB
/
StreamReaderNoClose.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.IO;
using System.Text;
namespace ZeroMQ
{
internal class StreamReaderNoClose : StreamReader
{
public StreamReaderNoClose(Stream stream) : base(stream)
{
}
public StreamReaderNoClose(Stream stream, bool detectEncodingFromByteOrderMarks) : base(stream, detectEncodingFromByteOrderMarks)
{
}
public StreamReaderNoClose(Stream stream, Encoding encoding) : base(stream, encoding)
{
}
public StreamReaderNoClose(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(stream, encoding, detectEncodingFromByteOrderMarks)
{
}
public StreamReaderNoClose(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize)
{
}
public StreamReaderNoClose(string path) : base(path)
{
}
public StreamReaderNoClose(string path, bool detectEncodingFromByteOrderMarks) : base(path, detectEncodingFromByteOrderMarks)
{
}
public StreamReaderNoClose(string path, Encoding encoding) : base(path, encoding)
{
}
public StreamReaderNoClose(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(path, encoding, detectEncodingFromByteOrderMarks)
{
}
public StreamReaderNoClose(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(path, encoding, detectEncodingFromByteOrderMarks, bufferSize)
{
}
protected override void Dispose(bool disposing)
{
// do nothing so the underlying stream will not be closed
}
/// <summary>
/// Description of StreamReader.ReadLine from MSDN:
/// A line is defined as a sequence of characters followed by a line feed ("\n"),
/// a carriage return ("\r"), or a carriage return immediately followed by a line
/// feed ("\r\n"). The string that is returned does not contain the terminating
/// carriage return or line feed. The returned value is null if the end of the
/// input stream is reached.
///
/// here we use Peek to check the EOF and return the line CONTAINING the terminating
/// \r, \n or \r\n to move the ZFrame position forward correctly
/// </summary>
public StringBuilder ReadLineWithTerminator()
{
if (Peek() == -1) return null;
StringBuilder sb = new StringBuilder();
while (true)
{
int c = Read();
if (c == -1) break;
sb.Append((char)c);
if (c == '\n')
break;
else if (c == '\r')
{
int c2 = Peek();
if (c2 == '\n')
sb.Append((char)Read());
break;
}
}
return sb;
}
}
}