blob: 2ceb643616762e60c225b3aeda1c9f2599db82e1 (
plain) (
blame)
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
|
using System;
using System.IO;
namespace Org.BouncyCastle.Utilities.IO
{
public class PushbackStream
: FilterStream
{
private int m_buf = -1;
public PushbackStream(Stream s)
: base(s)
{
}
public override int Read(byte[] buffer, int offset, int count)
{
Streams.ValidateBufferArguments(buffer, offset, count);
if (m_buf != -1)
{
if (count < 1)
return 0;
buffer[offset] = (byte)m_buf;
m_buf = -1;
return 1;
}
return base.Read(buffer, offset, count);
}
public override int ReadByte()
{
if (m_buf != -1)
{
int tmp = m_buf;
m_buf = -1;
return tmp;
}
return base.ReadByte();
}
public virtual void Unread(int b)
{
if (m_buf != -1)
throw new InvalidOperationException("Can only push back one byte");
m_buf = b & 0xFF;
}
}
}
|