Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# implementation of PushbackInputStream

Tags:

c#

I need a C# implementation of Java's PushbackInputStream. I have made my own very basic one, but I wondered if there was a well tested and decently performing version already available somewhere. As it happens I always push back the same bytes I read so really it just needs to be able to reposition backwards, buffering up to a number of bytes I specify. (like Java's BufferedInputStream with the mark and reset methods).

Update: I should add that I can't simply reposition the stream as CanSeek may be false. (e.g. when the input steam is a NetworkStream)

like image 541
Mark Heath Avatar asked Jul 03 '26 15:07

Mark Heath


1 Answers

The problem with pushing data back into a stream is that any readers that sit on top of the stream may already have a local buffer of data. This makes this approach very brittle. Personally, I would try to avoid this scenario, and use data constructs where I either don't need to push back, or can use single-byte Peek etc.

like image 127
Marc Gravell Avatar answered Jul 06 '26 05:07

Marc Gravell