[Mono-bugs] [Bug 43741][Wis] New - System.IO.StreamReader.Peek confuses end-of-line and end-of-file
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Tue, 27 May 2003 13:42:07 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by tonyg@lshift.net.
http://bugzilla.ximian.com/show_bug.cgi?id=43741
--- shadow/43741 Tue May 27 13:42:07 2003
+++ shadow/43741.tmp.6345 Tue May 27 13:42:07 2003
@@ -0,0 +1,91 @@
+Bug#: 43741
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details: RH linux 7.2, Windows XP sp1
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: tonyg@lshift.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.IO.StreamReader.Peek confuses end-of-line and end-of-file
+
+This code snippet, involving System.IO.TextReader.Peek (really
+StreamReader.Peek) appears to me to confuse end-of-line (actually,
+end-of-currently-available-input) with end-of-file when reading from
+System.Console.In (or any StreamReader?).
+
+This happens on both Mono 0.24 on Linux and MS .NET 1.1 on Windows XP.
+
+I'm trying to see if the stream is finished *without* advancing the stream
+position.
+
+1. am I using the API wrong? I hope so.
+2. if not, is this a bug in the implementation, or in the spec? or
+ is there a hole in the spec?
+
+Here's the output I get, when I type 123<ret> at it:
+
+ Peeking: 49
+ Reading: 49
+ read: 49 (1)
+ Peeking: 50
+ Reading: 50
+ read: 50 (2)
+ Peeking: 51
+ Reading: 51
+ read: 51 (3)
+ Peeking: 10
+ Reading: 10
+ read: 10 (
+ )
+ Peeking: -1
+ bye!
+
+(MS.NET on Windows is the same, except you get a 13 before the 10)
+
+I would expect it to block, waiting for the first char of the next line of
+input after the linefeed char was returned; instead it reports something
+operationally indistinguishable from end-of-file as soon as it sees the end
+of the first line.
+
+Here's the code:
+
+ using System;
+ using System.IO;
+ using System.Text;
+
+ public class rtcs2 {
+ public static void Main(String[] args) {
+ while (true) {
+ int ch = P();
+ if (ch == -1) {
+ // No more characters available.
+ // End of file?
+ System.Console.WriteLine("bye!");
+ break;
+ }
+ ch = R();
+ System.Console.WriteLine("read: "+
+ ch+" ("+((char)ch)+")");
+ }
+ }
+
+ private static int P() {
+ int r = System.Console.In.Peek();
+ System.Console.WriteLine("Peeking: "+r);
+ return r;
+ }
+
+ private static int R() {
+ int r = System.Console.In.Read();
+ System.Console.WriteLine("Reading: "+r);
+ return r;
+ }
+ }