Here’s the current (25-aug-10) implementation of InputStream::readEntireStreamAsString:
const String InputStream::readEntireStreamAsString()
mo.writeFromInputStream (*this, -1);
It seems possible for mo.writeFromInputStream to read less than the entire stream, but since InputStream::readEntireStreamAsString doesn’t look at the return value, it doesn’t know. As things are now, it wouldn’t have anything to compare the return value to, so we need a bigger change to pull this off.
OutputStream::writeFromInputStream knows when one of its calls to InputStream::read fails. To handle the case where the caller doesn’t know how much data to expect, would you consider changing the signature of OutputStream::writeFromInputStream to something like this:[code]/** Reads data from an input stream and writes it to this stream.
@param source the stream to read from @param maxNumBytesToWrite the number of bytes to read from the stream (if this is less than zero, it will keep reading until the input is exhausted) @param numWritten if provided, populated with the number of bytes written @returns false if either the read or write operation fails for some reason */ virtual bool writeFromInputStream (InputStream& source, int64 maxNumBytesToWrite, int *numWritten = 0);[/code]
I first thought of
virtual bool writeFromInputStream (InputStream& source, int64 maxNumBytesToWrite, int &numWritten); but that requires way more changes.
With this, and something like
virtual bool readEntireStreamAsString (String &contents); for InputStream::readEntireStreamAsString, callers can learn when errors have happened.
I’ll work on a patch to work this through if this seems like a reasonable way forward. Exceptions would be cleaner, but this helps in the meantime.