When writing unit tests of code rendering to a stream it would be very useful to have a character stream that would capture the output in-memory as a string rather than writing to a file, reading the file and having to delete the file.

In other words, an analogue for a ByteArrayOutputStream (Java) where output to a stream occurs.

This would allow unit testing of such procedures taking a stream as a parameter to be redirected to a character stream and relieve developers of the need to worry about running out of disk or file handles when running large numbers of unit tests.