title: Testing what's written to a Java OutputStream
body: <p>I am about to write junit tests for a XML parsing Java class that outputs directly to an OutputStream. For example <code>xmlWriter.writeString("foo");</code> would produce something like <code>&lt;aTag&gt;foo&lt;/aTag&gt;</code> to be written to the outputstream held inside the XmlWriter instance. The question is how to test this behaviour. One solution would of course be to let the OutputStream be a FileOutputStream and then read the results by opening the written file, but it isn't very elegant. </p>