Created
May 23, 2018 15:03
-
-
Save abc126/196cbd00ec9c2286d21e87c1c858dc4a to your computer and use it in GitHub Desktop.
PeekingStreamReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class PeekingStreamReader : StreamReader | |
| { | |
| private Queue<string> _peeks; | |
| public PeekingStreamReader(Stream stream) : base(stream) | |
| { | |
| _peeks = new Queue<string>(); | |
| } | |
| public PeekingStreamReader(string path) : base(path) | |
| { | |
| _peeks = new Queue<string>(); | |
| } | |
| public override string ReadLine() | |
| { | |
| if (_peeks.Count > 0) | |
| { | |
| var nextLine = _peeks.Dequeue(); | |
| return nextLine; | |
| } | |
| return base.ReadLine(); | |
| } | |
| public string PeekReadLine() | |
| { | |
| var nextLine = ReadLine(); | |
| _peeks.Enqueue(nextLine); | |
| return nextLine; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment