I got a HttpResponse.Filter filter that replaces text in the HTML.
I’ve created a class that derives from Stream and implemented the Write method:
public override void Write(byte[] buffer, int offset, int count)
I read all bytes from buffer and store them in a private StringBuilder, then I replace the text, and write the string back to the Stream.
But how can I determine when the stream is at the end of the stream. I.e. how do I determine when to write back the html (string) to the stream?
The
Readmethod returns the number of bytes read from the stream. It’s important that you take care of this value, as it can be less than the number of bytes requested, especially if the source of the stream is something slow like an internet connection.When the
Readmethod returns zero, you have reached the end of the stream.