Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

System.IO.Stream is seriously broken

HttpWebResponse type objects can give you a System.IO.Stream to read the body of the response.

The stream doesn't know how big it is, and can't seek.

This is ok, but there is no way to correctly read the response in all cases.

The code should be:

const int Capacitate=1000;

byte[] Buffer = new byte[Capacitate];

int count = ReadStream.Read(Buffer, 0, Capacitate);

while (count > 0)
    FResponseBody+=Ascii2Unicode(Buffer, count);
    count = ReadStream.Read(Buffer, 0, Capacitate);

Surprise, surprise!

The Read method never returns zero. :-(

I didn't expected this to be so fscking badly broken!

After the huge number of bugs I discovered in this, I only expect .NET to succeed only if it has huge marketing and lots of third-party support (to reimplement most broken things). I had very high hopes about .NET, but it turned out to be yet another plague inflicted on programmers, just like VB was.

I'm very disappointed.


Crane Michael
Thursday, July 24, 2003

I think it will succeed quite well! It's a v1.0 (1.1 if you're picky) implementation, there will be a few gremlins in the works... Java still has it's fair share of WTF moments... And it still seems to survive somehow... ;)

Andrew Cherry
Thursday, July 24, 2003

I've never had problems with this:

StreamReader reader = new StreamReader(request.GetResponseStream());
String stuff = reader.ReadToEnd();

Mr Michael -- calm down. Your tone of voice isn't particularly helpful.

Duncan Smart
Wednesday, July 30, 2003

Another thing: what is this:
  Ascii2Unicode(...) ???

Check out the System.Text.Encoding classes:
  using System.Text;
  string s = Encoding.ASCII.GetString(bytes);
  string s = Encoding.UTF8.GetString(bytes);

Duncan Smart
Wednesday, July 30, 2003



to get the length (in bytes) of the stream returned from HttpWebResponse.GetResponseStream  method ...

any class that overrides System.IO.Stream must provide an implementation of the Lenght() method

so to answer your question Mr. Michael, no the System.IO.Stream is not seriously broken... you just don;t seem to know how to properly use it ...

erhan hosca
Thursday, July 31, 2003

*  Recent Topics

*  Fog Creek Home