I do not think this is actually safe. `XppDriver.createWriter(OutputStream)` uses the default character encoding. It seems to me that `XStream.toXML(Object, OutputStream)` is simply unsafe to use for any purpose.

Perhaps `XStream2` should override it to write a header and then pass a `Writer` based on UTF-8? But it is unclear to me whether this method is always intended to write a complete document, or whether the result is ever used as a document fragment; `XmlFile.write` writes its own header, and various tests assert that there is no header in the output. So more compatible would be to override `XStream2.toXML(Object, OutputStream)` to write in UTF-8 encoding but not emit a header, and document this behavior (and then fix various callers to add their own header manually).

Overall this is all pretty sloppy; writing XML to a `Writer` is poor form; XML serialization is best done only to an `OutputStream`, and only when writing a complete document including encoding header. So another suggestion: add a new method `XStream2.toXMLWithHeader(Object, OutputStream)` which does the right thing, creating a deprecated no-op override of the original to remind callers to update.