Use StringWriter instead of writing directly to the stream.

There are some strange rules for UTF conversion and let's not reproduce them.